educative.io

Incorrect Test Case Output

Seems like test case expected output is incorrect (case 4) for the Reverse Nodes In Even Length Groups. The input is [11, 12, 13, 14, 15] and the output should be [11, 13, 12, 14, 15] where only group 2 should be reversed but the expected output is set to [11, 13, 12, 15, 14] where group 3 was incorrectly reversed.


Course: Grokking Coding Interview Patterns in Go - Learn Interactively
Lesson: Reverse Nodes In Even Length Groups

1 Like

Hello @joshpark,

Thank you for this feedback, but the expected output for this test case is correct. Let’s break it down to see how [11, 13, 12, 15, 14] is correct:

  • In the first group, there’s only 1 node, i.e., [11], so it will remain as it is.
  • In the second group, there are 2 complete nodes, i.e., [12, 13], so these will be reversed.
  • In the third group, there should be 3 nodes to make a complete group, but since there are only 2 remaining nodes, this group can also be reversed due to an even number of nodes.

Hence, the expected output becomes, [11, 13, 12, 15, 14].

I hope this clears your confusion regarding the test case. Please feel free to share further feedback and suggestions. We’d be happy to help. Thanks!

Happy learning!