Problems
August 13, 2022
Distinct subsequences
We will check each character of both string, when we find a match, then we have 2 choice, either we include the current index or we skip it. If we don't have a match, we we will skip the current...
ReadAugust 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...
ReadAugust 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)
,...
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...
ReadAugust 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...
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...
ReadAugust 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,...
ReadAugust 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...
ReadAugust 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...
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