Problems
December 25, 2022
Minimum number of moves to make palindrome
We will iterate over the string and count the number of moves for each character. We will update the result.
Time complexity: O(n^2)
Space complexity: O(1)
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
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
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 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
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 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
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 23, 2022
Convert binary search tree to sorted doubly linked list
We do an inorder traversal and make an arr of sorted nodes. We then create the doubly linked list by iterating through the array.
Time complexity: O(n)
Space complexity:...