Problems
December 25, 2022
Most popular video creator
We will count the number of videos for each creator. Then we will iterate over the videos and count the number of views for each creator. We will update the result. Time complexity:...
ReadDecember 25, 2022
Take k of each character from left and right
We will count the occurance of a, b and c. Then we will iterate over the string and take k characters from the left and right. We will update the result.
Time complexity: O(n)
Space...
December 25, 2022
Reward top k students
We will sort the students by their scores and then iterate over the students and reward them.
Time complexity: O(nlog(n))
Space complexity: O(n)
December 25, 2022
Count anagrams
It is obvious that the answer is the product of the number of unique permutations for each word in a sentence. The last one is just the number of permutations of all letters (treating same letters as...
ReadDecember 24, 2022
Beautiful array
We will use recursion to solve the problem. We will call the helper function on odd numbers and even numbers. We will return the result.
Time complexity: O(n)
Space complexity:...
December 24, 2022
Valid triangle number
We will sort the array. We will iterate over the array and use two pointers to find the number of valid triangles. We will return the result.
Time complexity: O(n^2)
Space...
December 24, 2022
Number of distinct islands
We will use a set to store the islands. We will iterate over the grid and call the dfs function on the current cell. We will return the result.
Time complexity: O(mn)
Space...
December 24, 2022
Custom sort string
We will use a hashmap to store the order of characters in order
. We will iterate over s
and store the characters in a list. We will sort the list using the order of...
December 24, 2022
Domino and tromino tiling
We will use dynamic programming to solve the problem. We will use dp[i]
to store the number of ways to tile i
units. We will use dp[i] = dp[i-1] + dp[i-2] + 2 *...
December 23, 2022
Count good meals
We will use a hashmap to solve this problem. We will iterate over the deliciousness
array and for each element, we will check if the element is a power of two. If it is, we will add the...