TGViewer
Coding Interview Preparation Coding Interview Preparation @coding_interview_preparation Β· 5.9K subscribers
Post #1367 347
🎯 CODING CHALLENGE #3 - Reverse a Linked List
Difficulty: Easy-Medium | Asked at: Amazon, Apple, Adobe

Reverse a singly linked list, iteratively.


Input: 1 β†’ 2 β†’ 3 β†’ 4 β†’ None
Output: 4 β†’ 3 β†’ 2 β†’ 1 β†’ None


πŸ’‘ Hint: You need to track three pointers as you walk the list: the previous node, the current node, and the next node - because once you flip a pointer, you lose the way forward unless you saved it first.

Solution:
python
class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next

def reverse_list(head):
prev = None
curr = head
while curr:
next_node = curr.next
curr.next = prev
prev = curr
curr = next_node
return prev


Complexity: O(n) time, O(1) space - this is the detail that separates a strong answer from an average one. A recursive solution is O(n) time but O(n) space due to the call stack - know both, and be ready to explain the tradeoff.

Common mistake: Forgetting to save curr.next before overwriting it, which permanently disconnects the rest of the list.

Iterative or recursive - which do you reach for first, and why? πŸ‘‡
  • ❀ 1
More from @coding_interview_preparation
  1. Oct 8, 2026If you're prepping for system design interviews, this repo is gold It contains a curated,…
  2. Oct 6, 2026document post
  3. Oct 4, 2026πŸ’Ό Why Your Resume Gets Rejected Before a Human Reads It You may have good skills and proj…
  4. Oct 2, 2026🧠 Coding Myths You Should Stop Believing There's a lot of advice online about learning to…
  5. Oct 1, 2026Most Asked Topics in AI Engineer Interviews Based on 2026 candidate reports
  6. Sep 30, 2026πŸ’Ό What Companies Actually Look For in a Fresher Think companies only care about your CGPA…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook β†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 β†’