Reverse subarray
Given a list of integers and two indices i and j with 0 <= i <= j < length, reverse the section of the list from position i through position j inclusive, leaving everything outside that window untouched, and return the list. Do it with swaps rather than building a new list. Example: [1, 2, 3, 4, 5] with i = 1, j = 3 becomes [1, 4, 3, 2, 5].
Implement
reverse_section(nums: list[int], i: int, j: int) → list[int]Examples
in
[[1,2,3,4,5],1,3]out[1,4,3,2,5]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 10 min
solution.py
InputExpectedGot
[[1,2,3,4,5],1,3][1,4,3,2,5]not run yetsample