PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Microsoft

Reverse a list in-place

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's ability to implement an in-place list reversal and the underlying competencies in array/list manipulation, index/pointer management, and analysis of space and time complexity.

  • easy
  • Microsoft
  • Coding & Algorithms
  • Data Scientist

Reverse a list in-place

Company: Microsoft

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

Implement a function that reverses a Python list in-place without allocating another list (no slicing, no list(), no reversed()). Requirements: O(n) time, O(1) extra space, and it must work for empty lists and odd/even lengths. Provide the function, brief correctness reasoning, and state the time/space complexity. Include tests that prove in-place behavior (e.g., the object id of the list is unchanged) and handle edge cases like [], [1], and [1, 4, 8, 12, 16, 20] → [20, 16, 12, 8, 4, 1].

Quick Answer: This question evaluates a candidate's ability to implement an in-place list reversal and the underlying competencies in array/list manipulation, index/pointer management, and analysis of space and time complexity.

Related Interview Questions

  • Sort Three Categories In Place - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Implement SFT Sample Packing - Microsoft (medium)
  • Implement SQL Table and DNA Ordering - Microsoft (medium)
  • Solve power jumps and graph tour - Microsoft (hard)
Microsoft logo
Microsoft
Oct 13, 2025, 9:49 PM
Data Scientist
Technical Screen
Coding & Algorithms
7
0

Coding Task: Reverse a List In-Place (Python)

Context

You're implementing a utility function during a technical screen. The function must reverse a Python list in-place without allocating another list.

Requirements

  • Implement a function that reverses a Python list in-place.
  • Constraints:
    1. No slicing (e.g., arr[::-1]), no list(), and no reversed().
    2. Time complexity: O(n).
    3. Extra space: O(1).
    4. Must work for empty lists, and for odd/even-length lists.
  • Deliverables:
    1. The function implementation.
    2. Brief correctness reasoning.
    3. Time and space complexity.
    4. Tests that demonstrate in-place behavior (e.g., object id unchanged) and cover edge cases like [], [1], and [1, 4, 8, 12, 16, 20] → [20, 16, 12, 8, 4, 1].

Solution

Show

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Microsoft•More Data Scientist•Microsoft Data Scientist•Microsoft 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.