Problems


January 31, 2023

Best team with no conflicts

We will sort the players by their score, and then we will iterate over the players and for each player we will find the best team that can be formed by including the current player. We will use a...

Read

January 29, 2023

Game of nim

We will calculate the XOR sum of all the piles, and check whether it's zero or not. For non zero value player 1 wins, otherwise player 2 wins. Time complexity: O(n) Space complexity:...

Read

January 29, 2023

LFU cache

We will create a hashmap to store the key-value pairs and a doubly linked list to maintain the frequency of each key. When a key is accessed, check if it exists in the hashmap. If it does, update its...

Read

January 28, 2023

Data stream as disjoint intervals

We will construct the interval by expanding around each of the added numbers. Time complexity: O(n) for getIntervals, O(1) for addNum Space complexity: O(n)

Read

January 27, 2023

Concatenated words

We can use the Trie data structure trie to store the words. Then for each word in the list of words, we use depth first search to see whether it is a concatenation of two or more words from the list....

Read

January 25, 2023

Find closest node to given two nodes

We will calculate distances between node1 and other reachable nodes. Then we will do the same thing for node2 too. Then we will iterate the nodes that are on the path for both distances and find max....

Read

January 24, 2023

Find minimum time to finish all jobs II

We can be greedy about the solution. We will sort all the workers and jobs, then iterate together to find the minimum time. We will start with the biggest worker and the biggest job. If the worker...

Read

January 23, 2023

Queue reconstruction by height

We can sort people by their height in descending order and if heights are equal, by the number of people in front of them in ascending order. Then we can insert each person into the result array at...

Read

January 22, 2023

Confusing number II

We can use backtracking to generate all possible numbers and check if they are confusing. We can generate all numbers with length from 1 to 9. For each length we can generate all numbers with digits...

Read

January 21, 2023

Candy

Go from left to right and while increase, give the the next person +1 candy from previous, if not, leave number of candies as it was. In this way when we make this pass we make sure that condition...

Read
... 5 6 7 8 9 ...