#K90597. Find the Out-of-Order Position
Find the Out-of-Order Position
Find the Out-of-Order Position
You are given a sequence of n integers. The sequence is sorted in non-decreasing order except for exactly one element which violates this order. Your task is to find the 1-indexed position of the first element that is out-of-order.
In a sorted (non-decreasing) sequence, for every valid index \(i\) (with \(2 \le i \le n\)), it must hold that:
[ a[i] \ge a[i-1] ]
If the condition fails at some position \(i\) (i.e. \(a[i] < a[i-1]\)), then the element at position \(i\) is considered out-of-order. It is guaranteed that there is exactly one such element in the sequence.
For example, given the sequence [1, 2, 6, 4, 8] of length 5, the condition \(6 \ge 2\) holds but fails at index 4 because \(4 < 6\). Thus, the answer is 4.
inputFormat
The input is given from stdin and consists of two lines:
- The first line contains a single integer \(n\), representing the number of elements in the sequence.
- The second line contains \(n\) space-separated integers representing the sequence.
outputFormat
Output to stdout a single integer: the 1-indexed position of the out-of-order element.
## sample5
1 2 6 4 8
4
</p>