โ† All coding problems

Binary search

MediumSearching

nums is sorted in ascending order. Return the index of target, or -1 if it is not present. Aim for O(log n).

Function
function solve(nums, target)
Example 1
nums = [1,3,5,7,9]
target = 7
โ†’ 3

Submit also runs 4 hidden tests, including edge cases.

console.log output is shown below