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.