Skip to content
Optimal Lab

Practice · 10 problems

Linked List

0 of 10 solved on this device

Watch it first · interactiveFast and slow pointers →Watch it first · interactiveLRU cache →Read the explainer · optimal-roundWhen to use it, and its look-alikes ↗
  1. 020Reverse Linked ListGiven the head of a singly linked list, reverse the list and return the new head. A node is { val, next }.Easy
  2. 021Merge Two Sorted ListsYou are given the heads of two sorted linked lists. Splice them together into one sorted list and return its head. The result must reuse the existing nodes.Easy
  3. 022Linked List CycleGiven the head of a linked list, determine whether the list contains a cycle. A cycle exists if some node can be reached again by continuously following `next`.Easy
  4. 023LRU CacheDesign a Least Recently Used cache with a fixed positive capacity. get(key) returns the value or -1; put(key, value) inserts or updates, evicting the least recently used key when over capacity. Both must run in O(1) average time.Medium
  5. 066Remove Nth Node From End of ListGiven the head of a linked list, remove the nth node from the end and return the head. Try to do it in one pass.Medium
  6. 067Add Two NumbersYou are given two non-empty linked lists representing non-negative integers whose digits are stored in REVERSE order, one digit per node. Add them and return the sum as a linked list in the same reverse-order form.Medium
  7. 068Merge k Sorted ListsYou are given an array of `k` linked lists, each sorted ascending. Merge them into one sorted linked list and return its head.Hard
  8. 110Palindrome Linked ListGiven the head of a singly linked list, return true if it reads the same forwards and backwards. Aim for O(n) time and O(1) space.Easy
  9. 111Intersection of Two Linked ListsGiven the heads of two singly linked lists, return the node where they intersect, or null if they never do. Intersection is by NODE IDENTITY, not value. Aim for O(1) extra space.Easy
  10. 112Copy List with Random PointerA linked list where each node has a `next` and a `random` pointer (which may point at any node or null). Return a DEEP COPY: new nodes whose pointers mirror the original structure but reference only copied nodes.Medium