Back to Practice
#0169

Reverse a Linked List Represented as Pairs

MediumDSA25 min20 XP

Problem

Given a dictionary next_map where each key points to the next node or None, and a head, return the new head after reversing the list.

Why This Matters

Pointer reversal is the central linked-list operation; this version makes the pointer state visible without a custom class.

Function Signature

def reverse_next_map(next_map, head):

Examples

Example 1
Inputnext_map = {'A':'B','B':'C','C':None}, head='A'
Output'C'

After reversal C points to B, B points to A, and A points to None.

Constraints

  • Return the exact requested output.
  • Handle ordinary edge cases.
  • Prefer simple, interview-readable code.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputnext_map = {'A':'B','B':'C','C':None}, head='A'
Expected'C'

After reversal C points to B, B points to A, and A points to None.

Hidden Test Categories
empty or minimal inputduplicates or tieslarger input