241. First Position At Least X
You are given n integers in non-decreasing order and a value x.
Print the smallest index i such that a[i] >= x. If every value is smaller
than x, print n.
This is the version of binary search worth learning properly, because plain "find the value" is a special case of it and this one also answers "where would it go if I inserted it".
Note what it returns when nothing qualifies: n, which is one past the last
valid index. That is deliberate and it is what makes the answer usable as an
insertion point.
Constraints - `1 ≤ n ≤ 200000` - `-1000000000 ≤ a[i] ≤ 1000000000` - `-1000000000 ≤ x ≤ 1000000000`
Input
The first line contains two integers n and x.
The second line contains n integers in non-decreasing order.
Output
Print one integer: the smallest index whose value is at least x, or n if there is none.
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.