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

0% completed

Vote For New Content
Why do we need to check only head_first_half and not the second_half as well?

Master Account

Jun 5, 2023

  if head_first_half is not None:     head_first_half.next = None

I am having trouble understanding why this portion of the code is needed at all. Why do we not have to do the same if statement for the head_second_half?

1

0

Comments
Comments
M
Mikhail Putilov2 years ago

I was wondering about that too.. Took me several hours to entangle that by myself :-) Here are my thoughts:

Disclaimer: The following is written about java version of the solution code.

Because of the way how we find the middle of the list, we have `head != null && he...

On this page