852. Peak Index in a Mountain Array
Approach 1: Return the largest number
The largest number will always be greater than it's neighbours so if just find the largest number and return it's index we will get the peak index
Time Complexity: O(N), both max and index are linear runtime functions
Space Complexity: O(1)
Approach 2: Binary Search for the Peak Index
Like any binary search we have the low and high initialized as 0 and the length of the array, and then we try to find not a specific number but a number that satisfies our criteria for peak index
Time Complexity: O(logN)
Space Complexity: O(1)
Last updated