Step 11 of 12 · Binary search

Binary search index

IntermediateJavaScript1,000 ms

Problem

Read a sorted list of distinct whole numbers and a target. Return the zero-based index of the target, or -1 when it is absent.

Input

The first line contains n. The second line contains n sorted integers. The third line contains the target.

Output

The target's zero-based index, or -1 when the target is absent.

Examples

Input
6
-4 0 3 7 12 20
7
Output
3

7 appears at zero-based index 3.

Input
4
2 5 8 11
6
Output
-1

6 does not appear in the sorted list.

Browser-isolated runner

Write your solution.

Define solve(input) and return the exact output. Network access is blocked and the runner stops after 1,000 ms. Run the example to inspect local console.log output.

Best verdictNot submitted
solution.jsLocal only
Keyboard: Tab to Run, then EnterSign in to submit
Try your own inputRuns locally without adding a saved attempt
Ready

You can run the example now. Sign in to submit and save progress.

Sign in to save this work. Your code, attempts, and Accepted progress return with your account.

Saved attempts

Verdict history

No saved submissions yet. Your first verdict will appear here.