Upper Bound
EasyP2Coding
nums is sorted in ascending order and may contain duplicates. Return the index of the first element that is strictly greater than k. If no element is greater than k, return nums.length.
Your solution must run in O(log n) time.
Example 1
- Input
- nums = [1,2,2,2,5], k = 2
- Output
- 4
Example 2
- Input
- nums = [1,3,5], k = 5
- Output
- 3
Example 3
- Input
- nums = [4,6], k = 1
- Output
- 0
Constraints
- 0 <= nums.length <= 10^5
- -10^9 <= nums[i], k <= 10^9
- nums is sorted in non-decreasing order
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 11. ⌘Enter runs, ⌘⇧Enter submits.