Problems
September 11, 2022
Minimum falling path sum
We will create a helper function that will calculate the minimum path from the starting row and and column. In the helper function we will check the boundary of the column, if it is out of boundary...
ReadSeptember 11, 2022
Number of restricted paths from first to last node
We will first create an adjacency list from the edge list. Then we run dijkstra's shortest path algorithm to get the shortest distance from first node every other node. Then we run DFS from first...
ReadSeptember 10, 2022
Best time to buy and sell stock II
We will create a helper function to calculate the max profit, in each step, we can either buy or if we already bought, then we can sell. And each of these steps, we can either take the item or skip...
ReadSeptember 10, 2022
Best time to buy and sell stock III
We will create a helper function to calculate the max profit, in each step, we can either buy or if we already bought, then we can sell. And each of these steps, we can either take the item or skip...
ReadSeptember 10, 2022
Best time to buy and sell stock IV
We will create a helper function to calculate the max profit, in each step, we can either buy or if we already bought, then we can sell. And each of these steps, we can either take the item or skip...
ReadSeptember 10, 2022
Coloring a border
We will run a DFS starting from given row and column and get all the nodes that are same color. If a node is not in perimeter of the same color region, the number of adjacent node will be 4 for this...
ReadSeptember 10, 2022
Count and say
As the title says, we just do what the question says. The base-case has already been provided. All we need to do now is to write the recursive calls. The answer to that is provided in the question as...
ReadSeptember 10, 2022
Island perimeter
We will run a DFS starting from given row and column and get all the nodes that are same color. If a node is not in perimeter of the same color region, the number of adjacent node will be 4 for this...
ReadSeptember 10, 2022
Maximum binary tree II
We will run a simple DFS to find the place and insert the new node there.
Time Complexity: O(n)
Space Complexity: O(n)
September 10, 2022
Maximum binary tree
We will recursively create our tree, we will take the largest number of the array and put it as root. Then we will create the left subtree with the left elements from the input of the root, and right...
Read