Problems
December 23, 2022
Count good meals
We will use a hashmap to solve this problem. We will iterate over the deliciousness
array and for each element, we will check if the element is a power of two. If it is, we will add the...
December 23, 2022
Flatten a multilevel doubly linked list
We will use a recursive DFS to solve this problem. We will iterate over the head
linked list and for each node, we will check if the node has a child. If it does, we will recursively...
December 22, 2022
Check if there is a path with equal number of 0s and 1s
We will use top-down dynamic programming to solve this problem. We will create a dfs
function to find if there is a path from the current node to the end node. We will return the result...
December 22, 2022
Largest values from labels
We will use a greedy approach to solve this problem. We will sort the values in descending order and then iterate over the values. We will keep track of the number of items with each label. We will...
ReadDecember 22, 2022
Sum of distances in tree
We will create a tree from the edges. We will create a sums
array to store the sum of distances from each node to all other nodes. We will create a counts
array to store the...
December 21, 2022
Find distance in a binary tree
We will use a recursive function to find the distance between two nodes. The function will return the distance between the two nodes if both nodes are in the tree. Otherwise, it will return...
ReadDecember 21, 2022
Largest merge of two strings
We will iterate through the two strings and compare the current character of each string. If the current character of word1
is greater than the current character of word2
,...
December 21, 2022
Maximal network rank
We will create an adjacency list to represent the graph. We will iterate through all pairs of cities and find the number of common neighbors. If the number of common neighbors is greater than the...
ReadDecember 21, 2022
Possible bipartition
We will create an adjacency list from the dislikes list. Then we start traversing the graph with BFS, and for each alternate level, we will assign one color. If two adjacent node has the same color,...
ReadDecember 20, 2022
Backspace string compare
We will create a helper function that will take a string and return the string after applying the backspace operation. To evaluate, we will append each character to a stack, and whenever we hit a...
Read