nums is sorted in non-decreasing order. For a target, the floor is the largest value in nums that is <= target, and the ceil is the smallest value that is >= target. Return [floor, ceil], using -1 for one that does not exist.
Example 1
Input:
floor_and_ceil([1, 2, 8, 10, 11, 12, 19], 5)
Output:
[2, 8]
The floor is 2 and the ceil is 8.
Example 2
Input:
floor_and_ceil([3, 4], 1)
Output:
[-1, 3]
Nothing is <= 1, so the floor is -1. The ceil is 3.
0 <= len(nums) <= 2 * 10**5nums is sorted in non-decreasing order.0 <= nums[i], target <= 10**9in, .index, .count, min or sorted on the whole list, fails them.No results yet
Run your code to check it against the examples, or submit to run every test.