Roblox | Find all the peaks
Anonymous User
4056

Question:
Given an array of integers, representing points in a graph, find all points which are the 'peak' points in a graph.

Arr: [ 1, 4, 3, -1, 5, 5, 7, 4, 8 ]

Peaks: [4, 7, 8]

If you plot the numbers in the array as a graph, you'll see it rising and falling based on the value. For a point to qualify as a 'peak', the graph should rise to the 'peak' and then fall, exceptions being the first and last elements. For the first element to be a peak, the graph should fall after it. For the last element to be a peak, the graph should rise before it.

Try to solve in O(n) time.

Comments (7)