242. How Many Times Does X Appear
You are given n integers in non-decreasing order. Print how many times
x appears.
Scanning the array works and is O(n). With 200000 values and the array
already sorted, you can do far better: the copies of x are all next to each
other, so find where they start and where they end.
Two binary searches, subtract, done. Each is about eighteen steps rather than two hundred thousand.
Constraints - `1 ≤ n ≤ 200000` - `-1000000000 ≤ a[i] ≤ 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 number of times x appears.
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.