This question evaluates proficiency with binary search, precise index and boundary management in sorted arrays, and the ability to reason about algorithmic correctness, loop invariants, and time/space complexity.
Implement two functions for a nondecreasing sorted integer array nums of length n: lower_bound(target) returns the smallest index i such that nums[i] >= target, or n if no such index exists; upper_bound(target) returns the smallest index i such that nums[i] > target, or n if no such index exists. Provide iterative implementations with O(log n) time and O(