#K80582. Find Leftmost Minimum and Rightmost Maximum in a Subarray
Find Leftmost Minimum and Rightmost Maximum in a Subarray
Find Leftmost Minimum and Rightmost Maximum in a Subarray
You are given an array of integers and two indices, start and end (0-indexed). Your task is to find:
- The index of the leftmost minimum element in the subarray arr[start..end].
- The index of the rightmost maximum element in the same subarray.
In other words, let \(L = \min\{arr[i] : start \le i \le end\}\) and \(R = \max\{arr[i] : start \le i \le end\}\). You should return the smallest index \(i\) within \([start, end]\) such that \(arr[i] = L\) and the largest index \(j\) within \([start, end]\) such that \(arr[j] = R\).
Note: The array indices are 0-based.
inputFormat
The input is given via stdin and has the following format:
- An integer n denoting the number of elements in the array.
- A line with n space-separated integers representing the array.
- A line with two space-separated integers, start and end, representing the range to consider.
outputFormat
Output to stdout a single line containing two space-separated integers:
- The index of the leftmost minimum element.
- The index of the rightmost maximum element.
6
2 3 1 4 1 5
1 4
2 3