Problems
October 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
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
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 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 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
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
Add binary
We will start from the end character of each number, add that and if the sum is more than 2, we take the reminder to the next digit, and add the last digit to our result. We will continue the process...
ReadOctober 4, 2022
Delete node in a linked list
As we are not given with head node, we will copy the value of next node to the current node. Then we remove the next node by moving the next pointer of current node to the next pointer of the next...
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