Problems
August 9, 2022
Valid parenthesis string
We will keep track of number of left parenthesis and number of right parenthesis in the string. For *
, we could count it as left parenthesis or right parenthesis or we could ignore it....
August 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 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
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 7, 2022
Count vowels permutation
We are going through the decision tree to map out all the possible combinations. The calculation will be kept in a 2-dimentional array, where each index will represent the combination of the string...
ReadAugust 7, 2022
Detect squares
We will keep track of each elements in a list and their respective points count in a hashmap. Whenever we add a point, we increment the points count and also add the point in points list. We we...
ReadAugust 7, 2022
Find median from data stream
We will use a min heap and a max heap to calculate the median. The small heap will be a max heap and large heap will be a min heap. All the elements of the small heap will be smaller than large heap....
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