l
(left) and r
(right) to the start and end of the array, respectively.l < r
.mid
as (l + r) / 2
.arr[mid] < arr[mid + 1]
, the peak must be to the right of mid
, so set l
to mid + 1
.mid
or to the left of mid
, so set r
to mid
.l
equals r
, the peak has been found, and l
(or r
) is the peak index.