Project Euler 18 test case not working

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]];


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:

Hi, your code is correct but you need to comment out the //console.log(maximumPathSumI(testTriangle));

This is because the console.log is interfering with test cases when you run the test you get two times 23 as output in console 1st 23 is from your console.log and second is from the test case due to this collusion 1 test case must have failed.

Just comment the line out and you are good to go.
Hope this answers your question.
Happy Coding :slightly_smiling_face:

1 Like

Thank you so much. Yes that was the issue and the test case passed

Hey @swwayam24 I am having this issue in the 20th question too but removing the console.log() doesn’t rectify it although the return values are correct.

Challenge: Problem 20: Factorial digit sum

Link to the challenge:

I would make a new post with your new problem.

@ujjwal29, please post your code and I suggest you create a new topic for your queries.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.