Problems


December 12, 2022

Lowest common ancestor of deepest leaves

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...

Read

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...

Read

December 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...

Read

December 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...

Read

December 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...

Read

December 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...

Read

December 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...

Read

December 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....

Read

December 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

December 10, 2022

Valid palindrome IV

We will use two pointers to check if the string is a palindrome. We will start from the beginning and the end of the string and we will check if the characters are the same. If they are not, we will...

Read
... 19 20 21 22 23 ...