CodeMentor.
Ask AIProblemsLearnC++TCSCore CSHRProgress
0Lv 1
ProblemsBinary Search

Binary Search

Easy
LeetCode
1/3
EasyBinary SearchLeetCode #704

Binary Search

Sorted array. Halve search space each step. Mid = L + (R-L)/2.

Examples

Example 1

Input

6 9
-1 0 3 5 9 12

Output

4
Example 2

Input

6 2
-1 0 3 5 9 12

Output

-1

Stuck? Take a nudge

C++17Autosaves