(pending)

Basic idea

Pseudocode

 
A = [1, 2, 6, 3, 4, 9, 7]
 
 

Runtime and memory analysis

The runtime here is since at every step we half our search space.

The memory usage is since we don’t use any extra datastructure.

On a sidenote

I highly recommend reading Zhijun Liao’s post on LeetCode. He explains a series of problems on LeetCode that could be solved by understanding how and when to apply Binary Search. He also shows a wonderful template that I highly recommend following.

— A

GitHub | Twitter