Pick the fix
Your O(1)-memory version passes all tests but a teammate's code breaks after calling it. Why?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A It leaves the second half turned around; turn it back before returning
Right: the caller's chain is now cut in half.
In-place tricks change shared data, so restoring it (or documenting it) is part of a complete answer.
Why not the others?
- B The slow pointer is too slow. Speed affects time, not the caller's data.
- C Python lists are immutable. They are not, and no list is involved here.