At Stripe, you need a fast lookup over a sorted list of numeric IDs. Implement binary search to find a target value in a sorted array.
Given a sorted array of integers nums in ascending order and an integer target, return the index of target if it exists. Otherwise, return -1.
nums: a list of integers sorted in non-decreasing ordertarget: an integer to search fornums[index] == target, or -1 if the target is not presentYour solution should use the binary search technique rather than a linear scan.
Example 1
Input: nums = [-1, 0, 3, 5, 9, 12], target = 9
Output: 4
9 appears at index 4.
Example 2
Input: nums = [-1, 0, 3, 5, 9, 12], target = 2
Output: -1
2 does not exist in the array.
0 <= len(nums) <= 10^5-10^9 <= nums[i], target <= 10^9nums is sorted in ascending ordernums are distinct