Iam_Sandeep

852. Peak Index in a Mountain Array Find the single peak in given mountain array

Aug 7th, 2022 (edited)
876
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. class Solution:
  2.     def peakIndexInMountainArray(self, a: List[int]) -> int:
  3.         l,r=0,len(a)-1
  4.         n=len(a)
  5.         while l<r:#After converging answer will be a[l] or a[r]
  6.             m=(l+r)>>1#compare with right one
  7.             if a[m]<a[m+1]:#Possibility of Peak here with m+1 hence l=m+1
  8.                 l=m+1
  9.             else:
  10.                 r=m
  11.         return l
Advertisement
Add Comment
Please, Sign In to add comment