Problems


September 22, 2022

Reverse words in a string III

We will split the words, then reverse each word indivisually, then merge them together and return as result. Time Complexity: O(n) Space Complexity: O(1)

Read

September 21, 2022

Sum of even numbers after queries

We will first calculate the sum of all even values. Then we follow the problem instruction, calculate the even sum after modifying the value according the query, then update the even sum and append...

Read

September 19, 2022

Find duplicate file in system

We will iterate over each path, extract the content, and based on the content, we will attach it to a hashmap where the key will be the content. Then we filter out the single files and return the...

Read

September 18, 2022

Number of sub arrays with odd sum

We will start counting both the odd and even numbers in the array. If the current number is even, then the number of odd subarray will the count of odd numbers. Otherwise, we will change the odd by...

Read

September 17, 2022

Deepest leaves sum

We will run a BFS to get the sum of each level, then return the last level sum as result. Time Complexity: O(n) Space Complexity: O(n)

Read

September 17, 2022

Iterator for combination

We will generate all the combination using backtracking and store it in the class. Then for each next call, we will increase our index and return the value of previous index. For hasNext, we will...

Read

September 16, 2022

Maximum score from performing multiplication operations

We will start from the beginning of the both array and calculate the left and right value recursively. Then we will compare them and return the highest result. We will then use memoization to reduce...

Read

September 16, 2022

Stone game

When the piles remaining are piles[i], piles[i+1], ..., piles[j], the player who's turn it is has at most 2 moves. The person who's turn it is can be found by comparing j-i to N modulo 2. If the...

Read

September 16, 2022

Minimum genetic mutation

We first convert the genetic sequence bank list to set for constant time lookup. If the end is not in bank, we immediately return -1. Else we start from start sequence, check every possible genetic...

Read

September 16, 2022

Minimum insertions to balance a parentheses string

We will iterate over each character, if the character is (, then we need 2 more, and if it is ), the we remove one from need. If the need is not even, then we add 1 in our...

Read
... 55 56 57 58 59 ...