Binary Search in a Sorted Array
Easy

Problem Statement

Given a sorted array of integers nums and an integer target, write a function to search for the target in nums. If the target exists, then return its index. Otherwise, return -1.

Examples

1Example 1
Input:
{ "nums": [ -1, 0, 3, 5, 9, 12 ], "target": 9 }
Output:
4
2Example 2
Input:
{ "nums": [ -1, 0, 3, 5, 9, 12 ], "target": 2 }
Output:
-1
3Example 3
Input:
{ "nums": [ 5 ], "target": 5 }
Output:
0
Loading...

Sign in to Run Code and Submit

    Binary Search in a Sorted Array – DSA Problem Solution | DSAPrime