Binary search: Given nums sorted in non-decreasing order and target, return the first index whose value is greater than or equal to target. Return nums.length when every value is smaller.
Input: A JSON object { "nums": number[], "target": number }.
Output: A JSON integer insertion index in the inclusive range 0..nums.length.
Constraints:
- 0 <= nums.length <= 100000
- nums is sorted in non-decreasing order
- Duplicates are allowed
Read one JSON value from stdin and print exactly one JSON-serialized answer to stdout with no extra text.
Difficulty: EASY. Variant: 7. Expect follow-up questions about complexity, edge cases, and alternative approaches.
Practice context
This coding (algo) exercise trains prompt interpretation, explicit assumptions, a concrete response, and a concise explanation of the decisions made. It is marked easy difficulty.
The signed-in workspace provides the