S
All challenges
Practice
Home
Blog
Practice
Examples
Feedback
Binary Search
00:00
Start
00:00
Sign in
Problem
Hints
3
Solution
History
Easy
Array
Binary Search
Divide & Conquer
TCS
Wipro
Amazon
Find target in sorted array. Return index if found, -1 if not. Must be O(log n).
Examples
Example 1
Input →
[-1,0,3,5,9,12], target=9
Output →
4
Example 2
Input →
[-1,0,3,5,9,12], target=2
Output →
-1
Example 3
Input →
[1], target=1
Output →
0
Example 4
Input →
[1,3], target=3
Output →
1
JavaScript
Python
Java (Coming soon)
C (Coming soon)
C++ (Coming soon)
Reset
Run
Submit
Cases
Results