Given a non-decreasing sorted array nums and a target value, implement two functions using binary search:
(
-
lower_bound(nums, target) that returns the smallest index i such that nums[i] >= target (return len(nums) if no such index exists);
(
-
upper_bound(nums, target) that returns the smallest index i such that nums[i] > target (return len(nums) if no such index exists). Achieve O(log n) time and O(
-
extra space, and handle duplicates, empty arrays, and targets outside the array’s value range. Clearly explain your boundary conditions and provide a few test cases to demonstrate correctness.