DescriptionQ883
Q883FWASIC interview problem
Find the middle node
TechniquesLinked listFast and slow
DifficultyEasy
TopicLinked Lists
LanguageSystemVerilog
Requirements3 checkpoints
01
Problem
Return the middle node of a singly linked list. For an even-length list, return the second of the two middle nodes.
Example input and output
Use this case to check your interpretationInput
head = 1 -> 2 -> 3 -> 4 -> nullOutput
node with value 3Explanation
With an even number of nodes, the fast pointer reaches null after slow advances to the second middle node.
02
Requirements (3)
- Use one traversal.
- Use constant extra space.
- Return null for an empty list.
