Problems


August 11, 2022

Pacific atlantic water flow

We will check the top row and left coulmn for pacific ocean and right column and bottom row for atlantic ocean. Then from each position of the grid, we will check whether we can reach pacific or...

Read

August 10, 2022

Maximum product subarray

We will keep track of minimum and maximum products of each item and keep the current maximum is our result. When the whole traversal is done, we will return the maximum result. Time Complexity:...

Read

August 10, 2022

Word break

We can solve the problem using BFS. We can model the problem as graph, every index can be considered as vertex and every edge is a completed word. Then the problem just boiled down if the path...

Read

August 10, 2022

Partition labels

We will first count the last position of all chacracter in a hashmap. Then we will iterate through the string, check if the last index of the chacracter is equal to the current index, if yes, then we...

Read

August 10, 2022

Decode ways

We could decode a string with 1 character with just 1 way, but if we have a 2 digit string, then we can decode it 2 ways. For example, 12 can be decoded 1->A, b->2 or...

Read

August 10, 2022

Convert sorted array to binary search tree

If there is no element in the sorted list, then we return null. This logic we will use as our base case. Then we will select the middle of the sorted list as our root node. Then from there, all the...

Read

August 9, 2022

Binary trees with factors

We will convert the array to array set, so that we can do the lookup in constant time. Then we will check, if a candidate can divide the root without any remainder and root//candidate is available in...

Read

August 9, 2022

Hand of straights

We will first check if the number of card is divisible by the group size, if not, we immediately return false. Then we count the number of cards, and create a min heap with all the distinct cards....

Read

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

Read

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

Read
... 76 77 78 79 80 ...