Problems
December 1, 2022
Evaluate the bracket pairs of a string
We will use a hashmap to store the key-value pairs. Then we will iterate over the string and if we encounter a (
, we will start a new string. If we encounter a )
, we will...
December 1, 2022
Factorial trailing zeroes
We will count the number of trailing zeroes in the factorial of the given number. We will count the number of 5s in the factorial of the given number. We will keep dividing the number by 5 and add...
ReadDecember 1, 2022
Single row keyboard
We will iterate over the word, find the index of the character in the keyboard and add the difference between the current and previous index to the result.
Time complexity: O(n)
...
November 30, 2022
Maximum split of positive even integers
We can be greedy and try to split the number into as many parts as possible. We will start from the 2 and try to split it until we reach the end of the number. If we can't split the number, we will...
ReadNovember 30, 2022
Unique word abbreviation
We will use a dictionary to store the count of each abbreviation, and a set to store the words that have been added to the dictionary. If the word is already present in the set, we will return false....
ReadNovember 30, 2022
Sparse matrix multiplication
We will iterate over the non-zero elements of the first matrix and multiply them with the corresponding elements of the second matrix. We will store the result in a dictionary and return the result....
ReadNovember 30, 2022
Recover a tree from preorder traversal
We save the construction path in a stack. In each loop, we get the number level of '-'. We get the value val of node to add. If the size of stack is bigger than the level of node, we pop the stack...
ReadNovember 30, 2022
Fizz buzz
We will iterate over the numbers from 1 to n and append the corresponding string to the result list. If the number is divisible by 3, we will append "Fizz" to the result list. If the number is...
ReadNovember 30, 2022
Find all lonely numbers in the array
We will count the occurrences of each number in the array and return the numbers that have only one occurrence and no adjacent number is present in the list.
Time complexity: O(n)
, n...
November 30, 2022
Unique number of occurrences
We will count the number of occurrences of each number in the array. We will then check if the number of occurrences is unique using a hash set.
Time complexity: O(n)
, n is the length...