Problems


August 13, 2022

Substring with concatenation of all words

We will create a haspmap with all the words count from the list, then we will start a sliding window, and checking the word is present in the string, then move forward by the length of each word....

Read

August 12, 2022

Redundant connection

We can use union find algorithm detect the cycle, and the edge that makes the cycle, that is our redundant edge. For union find, we will union the nodes by their rank. Initially all the rank will be...

Read

August 12, 2022

Longest increasing path in a matrix

We will run a DFS from each element of the matrix, and search from the longest increasing path. We will also memoize each repetative steps in the process, so we can solve it easily. Time...

Read

August 12, 2022

Walls and gates

We will run a BFS from every getes, and on the process we will replace every infinity value with the distance. Whenever we hit an obstacke, we will skip that. Time Complexity: O(n*m),...

Read

August 12, 2022

Interleaving string

We will solve the problem with brute force recursively. We will run a DFS in our decision tree, if i and j is equal to the length of s1 and s2, then we return true. Otherwise we will take either a...

Read

August 12, 2022

Longest common subsequence

We can solve the problem by brute force, we will compare each character of text1 and text2, then recursively store the longest matching sting length of these two string. Then we will use memoization...

Read

August 12, 2022

Word ladder

First we will create a adjacency list by the pattern, and the pattern will be replacing one character with *. Then we will run BFS in the graph, and count the number of iteration it...

Read

August 12, 2022

Best time to buy and sell stock with cooldown

We will solve the problem with brute force using a decision tree and run DFS with that. If our index is already out of bound we return 0, this will be our base case. From there, if we are buying,...

Read

August 11, 2022

Partition equal subset sum

This is basically a 0-1 knapsack problem, for each element, either we can take the element or leave it. First, we will check, if the sum of the numbers is not even, we immediately return false. Then...

Read

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
... 75 76 77 78 79 ...