Reverse a singly linked list robustly
Company: NVIDIA
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: hard
Interview Round: HR Screen
Quick Answer: This question evaluates linked-list manipulation skills including in-place iterative reversal, recursive techniques, cycle detection and handling, time and space complexity analysis, loop invariants, and minimal test design.
Examples
Input: ([1, 2, 3], None)
Expected Output: [3, 2, 1]
Explanation: Basic reversal.
Input: ([], None)
Expected Output: []
Explanation: Empty list.
Input: ([1], None)
Expected Output: [1]
Explanation: Single node.
Input: ([1, 2, 3, 4], 1)
Expected Output: [4, 3, 2, 1]
Explanation: Cycle policy is break before reverse.
Hints
- Iterative pointer reversal is O(1) extra space; detect cycles first when node references are available.