#C2908. Reverse Subarray
Reverse Subarray
Reverse Subarray
You are given an array of n integers and two indices l and r (1-based). Your task is to reverse the subarray from index l to r and output the modified array.
In other words, if the original array is \(a = [a_1, a_2, \dots, a_n]\), after reversing the subarray from \(l\) to \(r\), the new array becomes:
\(a' = [a_1, \dots, a_{l-1}, a_r, a_{r-1}, \dots, a_l, a_{r+1}, \dots, a_n]\)
You need to implement this functionality such that the solution works for all valid inputs.
inputFormat
The first line contains an integer n representing the number of elements in the array.
The second line contains n space-separated integers representing the elements of the array.
The third line contains two space-separated integers, l and r, representing the starting and ending indices of the subarray to be reversed (1-based index).
outputFormat
Output a single line containing the modified array with the subarray from l to r reversed, with each element separated by a space.
## sample5
1 2 3 4 5
2 4
1 4 3 2 5