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

Read

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

Read

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

Read

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

Read

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

Read

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

Read

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

Read

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

Read

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

Read

December 20, 2022

Ways to make a fair array

We will use odd prefix and even prefix to keep track of the sum of the odd and even indices. We will iterate through the array and keep track of the odd and even prefix. We will use a helper function...

Read
... 14 15 16 17 18 ...