Problems


December 12, 2022

Longest square streak in an array

We will use a greedy approach to solve this problem. We will keep on iterating over the sorted array and we will check whether the square of the number is available in the array. If it is available,...

Read

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

Longest univalue path

This problem is very similar to diameter of the tree problem. We will keep on iterating over the nodes of the tree and we will check whether the current node is the root of the longest univalue path....

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

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

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

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

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
... 19 20 21 22 23 ...