Given a sorted array of distinct integers and a target, return the index where the target is, or the index where it would be inserted to keep the array sorted.
Input
- Line 1: n (
1 ≤ n ≤ 10^5)
- Line 2: n sorted integers
- Line 3: the target
Output
A single 0-based index.
Hint
Plain binary search, but the answer is lo when the loop ends — that is the first position whose value is not smaller than the target.
Read from standard input and write to standard output. 5 test cases in total (3 hidden). Tests for this language run inside your browser.