Problems
October 6, 2022
Is subsequence
We will take two pointers, and then go through both string and increase the number of the pointers. When we exit the loop, if the pointer value of the first pointer is equal to the lenght of the...
ReadOctober 6, 2022
Replace elements with greatest element on right side
We will take the initial greatest element as -1. Then we start from the end of the array, replace the value with the greatest element and update the greatest element with the maximum of the greatest...
ReadOctober 6, 2022
Merge two binary trees
We will start form the root and run a DFS with both the tree and merge their value to the new tree and return that new tree as result.
Time Complexity: O(n)
Space Complexity:...
October 6, 2022
Length of last word
We will first start from the end and move the end pointer till we find a character. Then we take another pointer beginning from the end character and move towards the beginning of the string until we...
ReadOctober 6, 2022
Baseball game
We will use a stack to add the input and from there we will just follow the problem statement instruction. Finally we will return the sum of stack itself as result. Time Complexity:...
ReadOctober 5, 2022
Add one row to tree
We will recursively traverse the tree, and when we reach the level of the given depth, we insert nodes on both left and right subtree and return the value.
Time Complexity: O(n)
...
October 4, 2022
Palindrome number
We can convert the number to string, reverse it and then check whether it's palindrome of not.
Time Complexity: O(n)
Space Complexity: O(n)
First of all it the number...
October 4, 2022
N-queens II
We will have 3 different sets, one for the column, one for positive diagonal and one for negative diagonal. We will iterate over the each row, and try to add the queen in the board. If this is...
ReadOctober 4, 2022
Ugly number
If the number is negative, then it's not a ugly number. Then we do exactly what the problem statement says, we divide the number by 2, 3 and 5 until we can't divide it any more with these numbers. If...
ReadOctober 4, 2022
Remove covered intervals
We will sort the intervals by start with ascending order and end at decending order. Then we iterate over each intervals, if the end is greater than a right value, which is initially set as 0, then...
Read