A building access system stores its issued badge IDs in a single list sorted in strictly increasing order (all IDs are distinct). Given a query ID x, print the 0-indexed position of x in the list, or -1 if no badge has that ID.
Line 1: an integer n, the number of badge IDs.
Line 2: n space-separated integers in strictly increasing order.
Line 3: an integer x, the queried badge ID.
A single integer: the 0-indexed position of x, or -1 if absent.
Example 1
Input
6 -4 0 3 7 11 20 7
Expected
3
Explanation
The ID 7 is stored at index 3.
Example 2
Input
5 1 2 3 4 5 6
Expected
-1
Explanation
No badge has ID 6, so 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 →