Problems
December 12, 2022
Maximum level sum of a binary tree
We will traverse the tree with BFS and we will keep on iterating over the nodes of the tree. We will keep on adding the nodes of the current level to a queue and we will keep on adding the values of...
ReadDecember 12, 2022
Maximum nesting depth of two valid parentheses strings
We will keep on iterating over the string and we will keep on pushing the current character into the stack. If the current character is (
, we will increment the current depth. If the...
December 12, 2022
Smallest subtree with all the deepest nodes
We will traverse the tree with DFS and it will return the deepest depth of the tree and the lowest common ancestor of the deepest leaves. We will keep on iterating over the nodes of the tree and we...
ReadDecember 11, 2022
Best time to buy and sell stock with transaction fee
We will use top-down dynamic programming method to solve the problem. We will create a memoization table to store the maximum profit for each day. We will use a recursive function to calculate the...
ReadDecember 11, 2022
Minimum cost to connect sticks
We will use a heap to store the sticks. We will keep on popping the two smallest sticks from the heap and we will add their sum to the result. We will push the sum of the two sticks to the heap. We...
ReadDecember 11, 2022
Remove nodes from linked list
We will use recursion to remove the nodes from the linked list. If the current node is not a leaf node, we will check if the next node is a leaf node. If it is, we will remove the next node. If it is...
ReadDecember 11, 2022
Removing stars from a string
We will use a stack to store the characters of the string. If the current character is a star, we will pop the last character from the stack. If the current character is not a star, we will push it...
ReadDecember 10, 2022
Find the longest substring containing vowels in even counts
We will use a sliding window to solve this problem. We will keep track of the number of occurrences of each vowel in the window. We will then check if the number of occurrences of each vowel is even....
ReadDecember 10, 2022
Maximum product of splitted binary tree
We will calculate the sum of all nodes in the tree and then we will calculate the sum of all nodes in the left and right subtrees. The answer will be the maximum of the product of the sum of the left...
ReadDecember 10, 2022
Partition array such that maximum difference is k
We will sort the array and then we will iterate through the array and we will check if the difference between the current element and the previous element is greater than k, if it is, then we...
Read