educative.io

Unnesussary step

The problem statement says the left and the right pointers to be
1≤ left ≤≤ right ≤≤ n

That said, we dont really need to create a second pointer to iterate over to find the nth right element. Instead we can simply run over to reverse the list by K from the position found on the left site. Once reversed, the nth right element would be the one returned by the curr pointer.


Course: Grokking Coding Interview Patterns in Go - Learn Interactively
Lesson: Solution: Reverse Linked List II

Hello @Arkady,

Thank you for sharing this query, I’m having a bit difficulty in understanding your statement “Instead we can simply run over to reverse the list by K from the position found on the left site.” There’s actually no parameter K in the provided lesson link. However, the left and right pointers specifically mentioned in the problem statement of this lesson are helpful in finding the exact subarray to reverse and return it.

Can you please share more details regarding the code, or perhaps share a screenshot so that we can have a deeper look on the actually issue? Thanks!

Happy learning!