Problems


August 11, 2022

Surrounded regions

We will capture the surrounded reason by running DFS from each position and if it is not surrounded by the X, then we turn them into a temporary value T. Then after the DFS...

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

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

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

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

Longest palindromic substring

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

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