The iterative approach uses three pointers: prev, current, and next.
prev = null
current = head
while current != null:
next = current.next
current.next = prev
prev = current
current = next
return prev
Walk through this carefully. At each step:
Save current.next before overwriting it
Point current.next backward to prev
Advance prev and current one step
When current becomes null, prev points to the old tail, which is now the new head.
Time: . Space: .