#C9706. First Greater Element
First Greater Element
First Greater Element
You are given a list of integers. Your task is to determine the first integer in the list that is strictly greater than every integer that comes before it. In other words, find the smallest index i (with 1 ≤ i < n) such that
\(A[i] > \max \{ A[0], A[1], \ldots, A[i-1] \}\)
If no such integer exists, output -1
. Note that the first element is never considered because it does not have any preceding elements.
inputFormat
The input consists of two lines:
- The first line contains a single integer
n
(0 ≤ n ≤ 105), which represents the number of elements in the array. - The second line contains
n
space-separated integers representing the elements of the array. Ifn
is 0, the array is empty.
outputFormat
Output a single integer: the first integer in the list that is greater than all of its preceding integers. If no such integer exists, print -1
.
5
1 2 3 0 4
2