Problems
August 9, 2022
Merge triplets to form target triplet
We will iterate through all the triplets and if we found any of the items are greater than the value of target triplet, we ignore it from the consideration. Then we check if we found a value which is...
ReadAugust 8, 2022
Palindromic substrings
We will create a helper function to count the number of palindrome in a string starting from a left and right pointers. For odd number, both will be same index, for even left and right pointers will...
ReadAugust 8, 2022
House robber II
We can calculate the house robber using the same logic as the problem House robber, but we can't take the last element as it will create a circle. So, we can actually take 2 sets of numbers, one will...
ReadAugust 8, 2022
Longest increasing subsequence
First we append the first element in our list to the result array. Then we iterate over the other elements and compare, if the value is larger than the last element of the result array, if yes, then...
ReadAugust 8, 2022
Clone graph
First we will create a copy of the graph and put it on our hashmap. Then we run DFS for each neighbors to do the same thing, once the whole traverse it done, we will return the copy. Time...
ReadAugust 8, 2022
Gas station
We can be greedy to solve this efficiently. First we need to check if it is possible to complete the circut by calculating the difference between total gas and total cost. If cost is higher, we...
ReadAugust 7, 2022
Non overlapping intervals
First we will sort the intervals. Then we will iterate through all the intervals, compare if we have any collision between 2 consecutive interval, if yes, then we will count that, then after the...
ReadAugust 7, 2022
Multiply strings
We will first reverse both string and then calculate the first characters of both string, to get the digit. Then we store this digit at (i1+i2) position of our result. The (i1+i2+1) position will...
ReadAugust 7, 2022
Pow(x, n)
We will follow divide and conquar method to solve the problems. We we divide the n until it's a single digit, then the muliplication result is the number itself. When we merge it, we will join the...
ReadAugust 7, 2022
Insert interval
We will go through each interval, and compare the end of the new interval with the start of the current interval, if it doesn't collide, then just insert the new interval. Else, merge the interval...
Read