Problem statement

https://binarysearch.com/problems/Find-Local-Peaks/

Solution

Just do what is asked here.

Complexity

It is O(n) for time and space.

Code

class Solution:
    def solve(self, A):
        n = len(A)
        if n <= 1: return []
        ans = []
        for i in range(n):
            if i == 0:
                if A[i] > A[i + 1]: ans += [0]
            elif i == n - 1:
                if A[i] > A[i - 1]: ans += [n - 1]
            else:
                if A[i - 1] < A[i] > A[i + 1]: ans += [i]

        return ans