N-ary Tree Preorder Traversal Problem

N-ary Tree Preorder Traversal Problem Problem Given the root of an n-ary tree, return the preorder traversal of its nodes’ values. Nary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the null value (See examples) Examples Example 1: graph TD 1 --- A[3] & B[2] & C[4] A --- 5 & 6 ...

Reverse String 2 Problem

Problem Given a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string. If there are fewer than k characters left, reverse all of them. If there are less than 2k but greater than or equal to k characters, then reverse the first k characters and leave the other as original. Examples Example 1: ...

N-th Tribonacci Number Problem

N-th Tribonacci Number Problem Problem The Tribonacci sequence $T_n$ is defined as follows: $$ T_0 = 0, T_1 = 1, T_2 = 1, \text{ and }T_{n+3} = T_n + T_{n+1} + T_{n+2} \text{ for n} >= 0. $$ Given n, return the value of $T_n$. Examples Example 1: Input: n = 4 Output: 4 Explanation: T_3 = 0 + 1 + 1 = 2 T_4 = 1 + 1 + 2 = 4 ...

Maximum 69 Number Problem

Problem You are given a positive integer num consisting only of digits 6 and 9. Return the maximum number you can get by changing at most one digit (6 becomes 9, and 9 becomes 6). Examples Example 1: Input: num = 9669 Output: 9969 Explanation: Changing the first digit results in 6669. Changing the second digit results in 9969. Changing the third digit results in 9699. Changing the fourth digit results in 9666. The maximum number is 9969. ...

Make The String Great Problem

Make The String Great Problem Problem Given a string s of lower and upper case English letters. A good string is a string which doesn’t have two adjacent characters s[i] and s[i + 1] where: 0 <= i <= s.length - 2 s[i] is a lower-case letter and s[i + 1] is the same letter but in upper-case or vice-versa. To make the string good, you can choose two adjacent characters that make the string bad and remove them. You can keep doing this until the string becomes good. ...

Backspace String Compare Problem

Problem Given two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace character. Note that after backspacing an empty text, the text will continue empty. Examples Example 1: Input: s = "ab#c", t = "ad#c" Output: true Explanation: Both s and t become "ac". ...

Valid Perfect Square Problem

Problem Given a positive integer num, write a function which returns True if num is a perfect square else False. Follow up: Do not use any built-in library function such as sqrt. Examples Example 1: Input: num = 16 Output: true Example 2: Input: num = 14 Output: false ...

Intersection of Two Arrays 2 - Duplicates allowed

Problem Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may return the result in any order. Examples Example 1: Input: nums1 = [1,2,2,1], nums2 = [2,2] Output: [2,2] ...

Intersection of Two Arrays 1 - Unique Elements

Problem Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order. Examples Example 1: Input: nums1 = [1, 2, 2, 1], nums2 = [2, 2] Output: [2] ...

Nested List Weight Sum

Problem Given a nested list of integers, return the sum of all integers in the list weighted by their depth. Each element is either an integer, or a list – whose elements may also be integers or other lists. Examples Example 1: Input: [ [1,1],2,[1,1] ] Output: 10 Explanation: Four 1's at depth 2, one 2 at depth 1. ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy