← Back to Data Structures & Algorithms
Question 533
Reverse In Place
Reverse In Place
Write reverse_in_place(values: list[int]) -> None that reverses the list without building a new one: keep two indexes, left starting at 0 and right at the last position, and while left is below right swap the two elements through a temp variable, then move the indexes one step towards each other. This uses O(1) extra space. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: one line of space-separated integers (possibly empty); the tests call your function and then print the same list.
Expected Output:
[5, 4, 3, 2, 1]= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Data Structures & Algorithms
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.