Challenge
Given a nondecreasing array, return [lower, upper]. Lower is the first index whose value is at least target; upper is the first index whose value is strictly greater than target. Use len(nums) if no such value exists. Thus nums[lower:upper] contains all occurrences of target, possibly none.
Input and output contract
0 ≤ n ≤ 100,000; integer values and target with absolute value ≤ 1,000,000. Return insertion positions, not -1. Empty input returns [0, 0].
All tests follow this contract. You do not need to validate malformed input. Return the requested result from binary_search_boundaries; printed output is not your answer. Standard-library tools are allowed. Implement your solution in Python 3.12.
Target complexity: O(log(n + 1)) time; O(1) auxiliary space
Return values are checked by type. Use the exact function name. Print output is not your answer. Tests have time and memory limits.
Public examples
Arguments
[[1, 2, 2, 2, 5], 2]
Expected return
[1, 4]
Arguments
[[1, 2, 2, 2, 5], 3]
Expected return
[4, 4]
Arguments
[[], 9]
Expected return
[0, 0]
Hint
Use a half-open search interval [low, high). The two searches differ only in < versus ≤.
The worked solution unlocks after completion, or with Premium access.