The First Bad Reading
A cold-store probe at Riverbend Supply files one reading a minute, and the readings are kept in the order they arrived. A reading below zero means the probe has faulted. When engineers open a fault ticket they want to know where the trouble started, not how often it recurred, so the ticket carries a single position from the log. Every log they are given is known to contain at least one faulty reading.
Task: Print the position of the earliest faulty reading.
Input
The first line holds a single integer n, the number of readings. Each of the next n lines holds one reading, which may carry decimals and may be negative. At least one reading is below zero.
Output
One line holding that position, counted from 0: the first reading in the log sits at position 0, not position 1. Print the position, not the reading that sits there.
Example:
Input:
5
10
8
-3
5
-1
Output:
2
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in