CJCoding With Joseph
15free / daySign inCreate account

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
Topics:
Data Structures & Algorithms
📥 Auto-Input:
1 2 3 4 5\n
This input is automatically fed to your program's stdin
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.