Binary Search

Easy
ArrayBinary SearchMicrosoftGoogle
Given a sorted array of distinct integers in ascending order and a target, print the zero-based index of the target. Print -1 if the target is not present. Input format: - First line: n target - Second line: n integers in ascending order

Constraints

1 <= n <= 10^5
-10^9 <= nums[i], target <= 10^9
nums is sorted ascending with distinct values.

Sample tests

Sample 1

Sample 2

Sign in to submit