A radio observatory keeps a single logbook of incoming signal wavelengths, written down in the exact order they were measured. Every wavelength recorded so far is distinct, and the logbook is sorted from the smallest wavelength to the largest — the observatory could in principle keep extending the logbook forever, but you only need to work with the portion written down so far. A visiting researcher wants to know whether one particular wavelength was ever recorded, and if so, at what position in the logbook (counting from 0).
Line 1: a single integer n, the number of entries currently in the logbook. Line 2: n space-separated integers, the recorded wavelengths, strictly increasing from left to right. Line 3: a single integer, the wavelength the researcher is searching for.
Print a single integer: the 0-based position of the target wavelength in the logbook, or -1 if it was never recorded.
Example 1
Input
6 -10 -3 0 5 9 12 9
Expected
4
Explanation
The logbook holds six wavelengths in increasing order: -10, -3, 0, 5, 9, 12 at positions 0 through 5. The target 9 sits at position 4, so the answer is 4.
Example 2
Input
4 1 3 5 7 4
Expected
-1
Explanation
None of the four recorded wavelengths (1, 3, 5, 7) equals 4, so the target was never measured and the answer is -1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →