Tell us what’s happening:
The example test case of the matrix given below expects a return value of 23, which is being returned by the function but the test case is not being passed. The other 2 test cases have passed, indicating the code is correct
Your code so far
function maximumPathSumI(triangle) {
for (let i = triangle.length - 2; i >= 0; i--)
for (let j = 0; j <= i; j++)
triangle[i][j] += (triangle[i+1][j]>triangle[i+1][j+1]) ? triangle[i+1][j]:triangle[i+1][j +1];
return triangle[0][0];
}
const testTriangle = [[3, 0, 0, 0],
[7, 4, 0, 0],
[2, 4, 6, 0],
[8, 5, 9, 3]];
console.log(maximumPathSumI(testTriangle));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36 Edg/91.0.864.59
Challenge: Problem 18: Maximum path sum I
Link to the challenge: