Given a sorted array of integers nums and a target value, return the index of target using recursive binary search. If the target is not found, return -1.
Binary search works by repeatedly dividing the search space in half. Compare the target with the middle element — if they match, you are done. If the target is smaller, search the left half. If it is larger, search the right half.
You must solve this problem recursively — do not use loops.
nums = [1, 3, 5, 7, 9], target = 52nums = [1, 3, 5, 7, 9], target = 6-1nums = [], target = 1-10 <= nums.length <= 10^4-10^4 <= nums[i] <= 10^4nums is sorted in ascending orderAll values in nums are uniqueYou must use recursion (no loops)Run your code to see results
Use Cmd+Enter to run