#K68622. Ball Roll Stopping Index
Ball Roll Stopping Index
Ball Roll Stopping Index
Given the heights of a sequence of buildings, a ball starts rolling from the first building (index 0). The ball stops as soon as it encounters a building with a height greater than or equal to the height of the starting building. If no such building is found, the ball continues rolling and the function should return -1.
More formally, given a sequence \(h_0, h_1, \dots, h_{n-1}\), find the smallest index \(i > 0\) such that \(h_i \geq h_0\). If no such index exists, output -1.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains an integer \(n\), representing the number of buildings.
- The second line contains \(n\) space-separated integers, each representing the height of a building.
outputFormat
Output a single integer to standard output (stdout) — the index where the ball stops. If the ball never encounters a building with a height greater than or equal to the first building, output -1.
## sample6
5 3 6 7 4 2
2