Problems


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 17, 2022

Root equals sum of children

We will check the value of root with the sum of the rest of the tree. If the value of root is equal to the sum of the rest of the tree, then we will return True. Otherwise, we will...

Read

December 17, 2022

Apply discount to prices

We will split the sentence into words. Then we will iterate through the words, and for each word, if we found a word with the $ prefix, we will replace the amount with the discounted...

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

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

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

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

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
... 17 18 19 20 21 ...