Is the expected answer wrong?

  • 2

    My submission failed for this test case, but unless I misunderstood the question, I think mine is actually the expected output?

    Submission Result: Wrong Answer

    Input: {1,2,3,4}, 1, 4
    Output: {4,2,3,1}
    Expected: {4,3,2,1}

  • 5

    Your problem is that you switch the nodes at indices 1 and 4, while what you are supposed to be doing is reversing the list between those two nodes, inclusive. Therefore, 1->2->3->4 becomes 4->3->2->1.

  • 0

    I see, thanks mike3. The example given in the question is a little confusing :)

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.