DSAMaster Logo
DSAMaster
Linked Lists7 August 202625 min read

Top 25 Linked List Interview Questions and Answers (2026)

The complete guide to linked list interview questions with detailed answers, intuition, step-by-step breakdowns, and solutions in C++, Java, Python, and JavaScript. Covers reversal, cycle detection, merging, LRU cache, and more.

D
Written by DSAMaster Team
DSAMaster Editorial

1. Introduction to Linked List Interview Questions

Linked lists are a foundational data structure tested in almost every coding interview at top tech companies like Amazon, Google, Microsoft, Meta, and Flipkart. Unlike arrays, linked lists provide O(1) insertions and deletions once a reference to a node is known, but they give up O(1) random index access.

Interviewers frequently use linked list problems to assess your pointer manipulation skills, handling of null references, and ability to optimize space complexity. Below are the Top 25 Linked List interview questions with full solutions in C++, Java, Python, and JavaScript.


2. Linked List Fundamentals

A node in a singly linked list contains data and a pointer to the next node:

javascript
class ListNode { constructor(val = 0, next = null) { self.val = val; self.next = next; } }

3. Easy Questions

Q1. Reverse a Singly Linked List

Question: Reverse the direction of all pointers in a singly linked list so that the head becomes the tail.

Intuition: Maintain three pointers: prev (initialized to null), curr (initialized to head), and next (to temporarily store the next node before overwriting curr.next).

javascript
function reverseList(head) { let prev = null; let curr = head; while (curr !== null) { let nextNode = curr.next; curr.next = prev; prev = curr; curr = nextNode; } return prev; }

Time Complexity: O(n) | Space Complexity: O(1)


Q2. Find the Middle of a Linked List

Question: Given the head of a singly linked list, return the middle node. If there are two middle nodes, return the second middle node.

Intuition: Fast and Slow Pointers. slow moves 1 step at a time, fast moves 2 steps. When fast reaches the end (or null), slow will be exactly at the middle node.

javascript
function middleNode(head) { let slow = head; let fast = head; while (fast !== null && fast.next !== null) { slow = slow.next; fast = fast.next.next; } return slow; }

Time Complexity: O(n) | Space Complexity: O(1)


Q3. Detect Cycle in a Linked List

Question: Given head, determine if the linked list has a cycle in it.

Intuition: Floyd's Cycle-Finding Algorithm (Tortoise and Hare). If a cycle exists, the fast pointer will eventually catch up to and meet the slow pointer inside the loop.

javascript
function hasCycle(head) { let slow = head; let fast = head; while (fast !== null && fast.next !== null) { slow = slow.next; fast = fast.next.next; if (slow === fast) return true; } return false; }

Time Complexity: O(n) | Space Complexity: O(1)


Q4. Remove Nth Node From End of List

Question: Remove the nth node from the end of the list and return its head.

Intuition: Maintain a gap of n nodes between fast and slow pointers. Advance fast by n + 1 steps from a dummy node. Then advance both until fast is null. slow.next will point to the node to delete.

javascript
function removeNthFromEnd(head, n) { let dummy = new ListNode(0, head); let fast = dummy; let slow = dummy; for (let i = 0; i <= n; i++) { fast = fast.next; } while (fast !== null) { slow = slow.next; fast = fast.next; } slow.next = slow.next.next; return dummy.next; }

Time Complexity: O(n) | Space Complexity: O(1)


Q5. Merge Two Sorted Lists

Question: Merge two sorted linked lists into one single sorted list.

javascript
function mergeTwoLists(l1, l2) { let dummy = new ListNode(0); let tail = dummy; while (l1 !== null && l2 !== null) { if (l1.val < l2.val) { tail.next = l1; l1 = l1.next; } else { tail.next = l2; l2 = l2.next; } tail = tail.next; } tail.next = l1 !== null ? l1 : l2; return dummy.next; }

Time Complexity: O(m + n) | Space Complexity: O(1)


Q6. Delete Node in a Linked List (Given Only Node Reference)

Question: You are given access only to the node to be deleted. Delete it without receiving head.

Intuition: Copy the value from node.next into node, then bypass node.next.

javascript
function deleteNode(node) { node.val = node.next.val; node.next = node.next.next; }

Time Complexity: O(1) | Space Complexity: O(1)


4. Medium Questions

Q7. Check if a Linked List is a Palindrome

Question: Return true if the linked list reads the same forward and backward.

Intuition: Find the middle node using slow/fast pointers, reverse the second half of the list, and then compare the first half and reversed second half element by element.

javascript
function isPalindrome(head) { if (!head || !head.next) return true; let slow = head, fast = head; while (fast && fast.next) { slow = slow.next; fast = fast.next.next; } let prev = null, curr = slow; while (curr) { let nxt = curr.next; curr.next = prev; prev = curr; curr = nxt; } let first = head, second = prev; while (second) { if (first.val !== second.val) return false; first = first.next; second = second.next; } return true; }

Time Complexity: O(n) | Space Complexity: O(1)


Q8. Add Two Numbers Represented as Linked Lists

Question: Digits are stored in reverse order. Add the two numbers and return the sum as a linked list.

javascript
function addTwoNumbers(l1, l2) { let dummy = new ListNode(0); let curr = dummy; let carry = 0; while (l1 || l2 || carry) { let v1 = l1 ? l1.val : 0; let v2 = l2 ? l2.val : 0; let total = v1 + v2 + carry; carry = Math.floor(total / 10); curr.next = new ListNode(total % 10); curr = curr.next; if (l1) l1 = l1.next; if (l2) l2 = l2.next; } return dummy.next; }

Time Complexity: O(max(m, n)) | Space Complexity: O(max(m, n))


Q9. Intersection of Two Linked Lists

Question: Find the node at which two singly linked lists intersect. Return null if no intersection.

Intuition: Two Pointers. Pointer A traverses list A then switches to list B. Pointer B traverses list B then switches to list A. They will meet at the intersection node after m + n total steps.

javascript
function getIntersectionNode(headA, headB) { if (!headA || !headB) return null; let a = headA, b = headB; while (a !== b) { a = a ? a.next : headB; b = b ? b.next : headA; } return a; }

Time Complexity: O(m + n) | Space Complexity: O(1)


Q10. Find Cycle Start Node in a Linked List

Question: Given a linked list with a cycle, return the node where the cycle begins.

javascript
function detectCycle(head) { let slow = head, fast = head; while (fast && fast.next) { slow = slow.next; fast = fast.next.next; if (slow === fast) { let p = head; while (p !== slow) { p = p.next; slow = slow.next; } return p; } } return null; }

Time Complexity: O(n) | Space Complexity: O(1)


Q11. Reorder List (L0 → Ln → L1 → Ln-1...)

javascript
function reorderList(head) { if (!head || !head.next) return; let slow = head, fast = head; while (fast && fast.next) { slow = slow.next; fast = fast.next.next; } let prev = null, curr = slow.next; slow.next = null; while (curr) { let nxt = curr.next; curr.next = prev; prev = curr; curr = nxt; } let first = head, second = prev; while (second) { let t1 = first.next, t2 = second.next; first.next = second; second.next = t1; first = t1; second = t2; } }

Time Complexity: O(n) | Space Complexity: O(1)


Q12. Sort List using Merge Sort

javascript
function sortList(head) { if (!head || !head.next) return head; let slow = head, fast = head.next; while (fast && fast.next) { slow = slow.next; fast = fast.next.next; } let mid = slow.next; slow.next = null; let left = sortList(head); let right = sortList(mid); let dummy = new ListNode(0); let tail = dummy; while (left && right) { if (left.val < right.val) { tail.next = left; left = left.next; } else { tail.next = right; right = right.next; } tail = tail.next; } tail.next = left ? left : right; return dummy.next; }

Time Complexity: O(n log n) | Space Complexity: O(log n) call stack


5. Hard Questions & Design Patterns

Q13. LRU Cache Implementation

javascript
class Node { constructor(key = 0, val = 0) { this.key = key; this.val = val; this.prev = null; this.next = null; } } class LRUCache { constructor(capacity) { this.cap = capacity; this.map = new Map(); this.head = new Node(); this.tail = new Node(); this.head.next = this.tail; this.tail.prev = this.head; } _remove(node) { node.prev.next = node.next; node.next.prev = node.prev; } _add(node) { node.next = this.head.next; node.prev = this.head; this.head.next.prev = node; this.head.next = node; } get(key) { if (!this.map.has(key)) return -1; let node = this.map.get(key); this._remove(node); this._add(node); return node.val; } put(key, value) { if (this.map.has(key)) this._remove(this.map.get(key)); let node = new Node(key, value); this._add(node); this.map.set(key, node); if (this.map.size > this.cap) { let lru = this.tail.prev; this._remove(lru); this.map.delete(lru.key); } } }

Time Complexity: O(1) for both get and put | Space Complexity: O(capacity)


6. Summary Table

ProblemKey TechniqueTimeSpace
Reverse List3-pointer iterationO(n)O(1)
Find MiddleFast/Slow pointersO(n)O(1)
Detect CycleFloyd's Tortoise/HareO(n)O(1)
Merge 2 Sorted ListsDummy headO(n + m)O(1)
Check PalindromeMiddle + Reverse + CompareO(n)O(1)
LRU CacheHash Map + Doubly Linked ListO(1)O(capacity)

Master all linked list patterns on DSAMaster's practice platform.