Skip to main content

← Searching and sorting

Find the position

easy

The first line has n and a target. The second has n integers in increasing order (no repeats). Print the 0-based position of the target, or -1 if it is not there.

Example 1: input

6 9
-1 0 3 5 9 12

Output

4

Example 2: input

6 2
-1 0 3 5 9 12

Output

-1

Plus 2 hidden tests when you check your answer.

Your solution

Read from standard input and print the answer. Run it on the examples as often as you like, then check it against every test.

Stuck?

Open hints one at a time. The write-up explains a full solution.

Discussion

Ask a question or share a tip. Please don’t post full solutions. Posts appear once a moderator approves them.

No posts yet.