Problems


December 17, 2022

Minimum rounds to complete all tasks

We will count the different tasks and calculate the number of rounds for each task. Then we will return the maximum number of rounds. Time complexity: O(n) Space complexity:...

Read

December 17, 2022

Number of boomerangs

We will use a hashmap to store the distance between each point and the current point. Then we will iterate through the hashmap to calculate the number of boomerangs. Time complexity:...

Read

December 17, 2022

Replace elements in an array

We will use a hashmap to store the index of the input array for constant time lookup. Then we will iterate through the operations, and for each operation, we will update the value of the input array....

Read

December 16, 2022

Widest pair of indices with equal range sum

We will use a prefix sum approach to solve this problem. We will create a prefix sum array. We will create a hashmap. We will iterate through the prefix sum array. We will calculate the difference...

Read

December 16, 2022

Number of closed islands

We will use a DFS approach to solve this problem. We will iterate through the grid. We will check if the current cell is a land. We will check if the current cell is a closed island. We will return...

Read

December 16, 2022

Encode number

The following sequence can be built up form the ealier result. So we can search index of the prefix part, for example: f(5) = "10", f(6) = "11" The prefix are both f(2) = "1" so we found that f(n)...

Read

December 15, 2022

Campus bikes II

We will use a dynamic programming approach to solve this problem. We will create a memoization table. We will iterate through the memoization table. We will iterate through the bikes. We will check...

Read

December 14, 2022

Minimum number of operations to move all balls to each box

The question needs to search for balls left and right relative to the current box. If we use [1,1,0] as example, in the second box (i.e. boxes[1]): You will need to find the first box value (go...

Read

December 14, 2022

Ugly number III

We will use a binary search approach to solve this problem. We will find the smallest number that is divisible by a, b, and c. We will find the smallest number...

Read

December 14, 2022

Append k integers with minimal sum

We will use a greedy approach to solve this problem. We calculate the sum of the first k integers. We will iterate over the array and if the current number is less than k,...

Read
... 17 18 19 20 21 ...