Problems
July 18, 2022
Encode and decode string
We will join the array using $$
as delimeter, and also split the string with $$
to get it back.
Time Complexity: O(n), where n is the length of the array
Space...
July 18, 2022
Find largest value in each tree row
This is a classic BFS problem. We will traverse the tree with BFS and we will find the maximum value in each level. After each level is done, we will push the max value in our result array. After the...
ReadJuly 18, 2022
Minimum path sum
We will first solve it with brute force using recursion and then use memoization to make it efficient. For recursion, we can think about the base case, if our current position is out of bound, then...
ReadJuly 18, 2022
Lowest common ancestor of a binary search tree
We are guranteed to find a common ansestor. That means if the 2 values of p and q have their value both on left side or the tree root, right side of the tree root or opposite side of tree root. As...
ReadJuly 17, 2022
Target sum
We will first solve it with brute force using recursion and then use memoization to make it efficient. For recursion, we can think about the base case, we will start our index at the number of...
ReadJuly 17, 2022
Coin change
This is a classing dynamic programming problem. First we will solve it in brute force and then memoization(top-down) to reduce complexity.
Time Complexity: O(n*a)
, n is the number of...
July 17, 2022
House robber
We will first solve this with brute force and then use memoization to optimize our solution. For this problem, if we have no item, then the sum would be zero, so it would be our base case, we have 2...
ReadJuly 17, 2022
Unique paths
We will first solve it with brute force using recursion and then use memoization to make it efficient. For recursion, we can think about the base case, if our current position is out of bound, then...
ReadJuly 17, 2022
Best time to buy and sell stock
This is a classic sliding window problem. We will take 2 pointers, left pointer at the first element and right pointer as the second element. Then we forward right pointer and compare if the value at...
ReadJuly 16, 2022
Valid parentheses
We can iterate over each characters of the string, and if it's a opening braket, we push it to the stack. If not, then we check, if it matches the top of the stack braket. If matches then we pop it...
Read