Calculating the Minimum Sum Path in a Triangle (LeetCode Problem) Given a triangle array, return the minimum path sum from top to bottom. For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to either index i or index i + 1 on the next row. public static int minSumPathMemo(int[][] triangle) This method will calculate the minimum sum path in the triangle using the top down strategy. Note this method MUST BE recursive and you will need to create a recursive helper method. public static int minSumPathBottomUp(int[][] triangle) This method will calculate the minimum sum path in the triangle using the bottom up strategy. Note this method CANNOT be recursive and you should not create any additional helper functions. Extra Challenge: Could you do this using only O(n) extra space where n is the total number of rows in the triangle? This is method signature class below: package dynamic; public class MinSumPath { public static int minSumPathMemo(int triangle[][]) { return 0; } public static int minSumPathBottomUp(int triangle[][]) { return 0; } }
Calculating the Minimum Sum Path in a Triangle (LeetCode Problem)
Given a triangle array, return the minimum path sum from top to bottom. For each step, you may move to
an adjacent number of the row below. More formally, if you are on index i on the current row, you may
move to either index i or index i + 1 on the next row.
public static int minSumPathMemo(int[][] triangle)
This method will calculate the minimum sum path in the triangle using the top down strategy. Note this
method MUST BE recursive and you will need to create a recursive helper method.
public static int minSumPathBottomUp(int[][] triangle)
This method will calculate the minimum sum path in the triangle using the bottom up strategy. Note this
method CANNOT be recursive and you should not create any additional helper functions.
Extra Challenge: Could you do this using only O(n) extra space where n is the total number of rows in the
triangle?
This is method signature class below:
package dynamic;
public class MinSumPath {
public static int minSumPathMemo(int triangle[][]) {
return 0;
}
public static int minSumPathBottomUp(int triangle[][]) {
return 0;
}
}
Trending now
This is a popular solution!
Step by step
Solved in 6 steps with 4 images