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)
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...
ReadSeptember 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...
ReadSeptember 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...
ReadSeptember 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)
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...
ReadSeptember 16, 2022
Finding pairs with a certain sum
We will create 2 counter for both nums1 and nums2 and also we will keep track of nums2. Every time we add something, we increase the value in nums2, and update the counter. The for count, we will...
ReadSeptember 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...
ReadSeptember 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...
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