Code RoomReverse range in place
EasyPrep Room Coding #602

Reverse range in place

CodingAlgorithms & data structuresEntry–Mid~10 min

Given an integer array nums and two valid 0-based indices left and right with left <= right, reverse the elements from left to right inclusive, leaving everything outside that range untouched, and return the array. Do the reversal in place by swapping from both ends of the range — no slicing out a sub-array and rebuilding. Example: nums = [1, 2, 3, 4, 5], left = 1, right = 3 gives [1, 4, 3, 2, 5].

Implement
reverse_segment(nums: list[int], left: int, right: 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
InputExpectedGot
[[1,2,3,4,5],1,3][1,4,3,2,5]not run yetsample