Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
This does not look like it reverts the head to its original form.For input [1,2,...

Avinash Agarwal

Mar 15, 2022

This does not look like it reverts the head to its original form. For input [1,2,2,2,1] head: null slow: [2,2,1] fast: [1] headSecondHalf: null copyHeadSecondHalf: [1]

1

0

Comments
Comments
Design Gurus
Design Gurus4 years ago

How are you evaluating these? For example, 'head' could be null within the function isPalindrome().

You have to check these in the main function. Try iterating the head in the main, it should point to the same linked list.

T
Thilak G4 years ago

The second half becomes its own linked list and the reverse back at the end does not put the linked list to it's original state ?

2 -> 4

Second half Null

On this page