# Local maxima and minima of array

• Given an array, find out the indices of all the local maxima and minima.
A local maximum of an array a[0], a[1], ..., a[n-1] is defined as a[i] such that there exist k1 and k2 satisfying k1<=i<=k2, with
a[k1]=..=a[i]=...=a[k2], a[k1-1]<a[k1] if k1-1>=0 and a[k2]>a[k2+1] if k2+1<n.
Similarly, a local minimum is defined as a[i] such that there exist k1 and k2 satisfying k1<=i<=k2, with
a[k1]=..=a[i]=...=a[k2], a[k1-1]>a[k1] if k1-1>=0 and a[k2]<a[k2+1] if k2+1<n.

Example:
Input:
2 4 6 3 3 3 5 7 8 9 1

Output:
0 2 3 4 5 9 10

• @lintest Do you intend to post to the "Interview Questions" category instead? By the way please read this first.

• This is a problem I encountered during work. I do not actually know any company asks this question. I appreciate it if you could help me to put it in correct category!

• @lintest ohh I see. Then maybe you want to clarify that in the problem description. The category for general discussions should be fine.

• Just wanted to write that I saw a version of this question asked during my Facebook phone screen. Instead the input could only decrease or increase by 1 for each consecutive value. ie 1,2,3,4,3,2,1

• @lintest I just got asked this question in my Facebook final round

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.