PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/NVIDIA

Reverse a singly linked list robustly

Last updated: Mar 29, 2026

Quick Overview

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.

  • hard
  • NVIDIA
  • Coding & Algorithms
  • Data Scientist

Reverse a singly linked list robustly

Company: NVIDIA

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: hard

Interview Round: HR Screen

Reverse a singly linked list in place. Provide: 1) An iterative O(1)-extra-space solution and a recursive version; explain how you avoid stack overflow for up to 10^6 nodes (tail recursion elimination or chunked recursion). 2) Handling of edge cases: empty list, single node, very long list. 3) Behavior on cyclic lists: detect a cycle (Floyd’s) and either preserve the cycle orientation while reversing the linear segment or break the cycle—justify your choice and implement accordingly. 4) Time/space analysis, loop invariant for correctness, and minimal set of tests.

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.

Related Interview Questions

  • Return all file paths via DFS - NVIDIA (easy)
  • Implement a disk space manager with eviction - NVIDIA (medium)
  • Implement short algorithms on logs, grids, and strings - NVIDIA (hard)
  • Implement encode/decode for list of strings - NVIDIA (easy)
  • Solve small string and API tasks - NVIDIA (medium)
NVIDIA logo
NVIDIA
Oct 13, 2025, 9:49 PM
Data Scientist
HR Screen
Coding & Algorithms
2
0

Reverse a Singly Linked List In-Place

Context: You are given the head of a standard singly linked list (each node has value and next). Implement and explain robust reversal routines that work for empty lists, single-node lists, very long lists (up to 10^6 nodes), and lists that may contain a cycle.

Requirements

  1. Implement two versions:
    • Iterative reversal with O(1) extra space.
    • Recursive reversal. Explain how you avoid stack overflow for up to 10^6 nodes using either tail-recursion elimination (where available) or chunked recursion.
  2. Edge cases:
    • Empty list.
    • Single node.
    • Very long list (≈ 10^6 nodes).
  3. Cycles:
    • Detect a cycle using Floyd’s tortoise–hare algorithm.
    • Choose one policy:
      • Preserve the cycle orientation while reversing the linear segment, or
      • Break the cycle before reversing.
    • Justify your choice and implement accordingly.
  4. Include:
    • Time and space complexity analysis.
    • A loop invariant to argue correctness of the iterative solution.
    • A minimal but sufficient test set.

Solution

Show

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More NVIDIA•More Data Scientist•NVIDIA Data Scientist•NVIDIA Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.