Problems
August 16, 2022
N-th tribonacci number
This problem is just like fibonacci number, we will first solve it recursively and then memoize it to reduce redundant calculation.
Time Complexity: O(n)
Space Complexity:...
July 21, 2022
Prime number of set bits in binary representation
This is a very strait forward problem. We will have 2 helper function, one is for counting the number of bits in an integer and another for checking if the number is prime or not. Then we iterate...
ReadAugust 15, 2022
Roman to integer
We can replace characters like IV
or IX
to IIII
and VIIII
. In that way, when we calculate our result, we can just translate the value to integer...
August 14, 2022
Word ladder II
We will first run a BFS to create the graph with adjacency list. Then we will run DFS to find all possible paths of that graph.
Time Complexity: O((n+m)*l)
, n is the number of words,...
August 14, 2022
Next greater element I
We traverse nums2 and start storing elements on the top of stack. If current number is greater than the top of the stack, then we found a pair. Keep popping from stack till the top of stack is...
ReadAugust 13, 2022
Substring with concatenation of all words
We will create a haspmap with all the words count from the list, then we will start a sliding window, and checking the word is present in the string, then move forward by the length of each word....
ReadAugust 13, 2022
Edit distance
To compute the minimum distance, we will recursively call our decision tree. If i is 0, then we need to insert j characters, if j = 0, then we need in delete i characters. This will be our base case,...
ReadAugust 13, 2022
Design circular queue
We can implement a circular queue by using an array, the maximum size of the array will be the given input k. Then we will keep 2 pointers, one for head and one for tail, and whenever we enqueue some...
ReadAugust 13, 2022
Regular expression matching
We will go through our decision tree, and then we have 2 choices, either we take the * or we skip it. Based on this logic, we will create a recursive DFS solution for our problem. Then we memoize it...
ReadAugust 13, 2022
Stream of characters
We can use a trie to search efficiently in the stream. When we initially create our StreamChecker class, we will insert every word in reverse word. Then whenever we search for a character, we add...
Read