Find Local Maxima in Sensor Data
Learn this problemProblem statement
Imagine that you are working on a model to predict anomalies in temperature fluctuations. The data is collected in continuous streams from sensors, which you need to clean to develop an initial set of test data. Given an array of integers rawData representing temperature values, and an integer localArea, find every local maximum within rawData.
rawData[i] is considered to be a local maximum if, starting from rawData[i], localArea numbers to the left and localArea numbers to the right both form strictly decreasing subsequences. If there are less than localArea numbers to the left (or to the right) of rawData[i], take all numbers on that side into account when computing the local maximum.
In other words, rawData[i] is a local maximum if both of the following conditions are true:
rawData[i] > rawData[i + 1] > rawData[i + 2] > ... > rawData[i + localArea]orrawData[i] > rawData[i + 1] > rawData[i + 2] > ... > rawData[length(rawData) - 1]rawData[i] > rawData[i - 1] > rawData[i - 2] > ... > rawData[i - localArea]orrawData[i] > rawData[i - 1] > rawData[i - 2] > ... > rawData[0]
Return an array of integers containing the 0-based indices of all local maximums within rawData. Elements of this array should be sorted in ascending order.
Function
findLocalMaxima(rawData: int[], localArea: int) → int[]Examples
Example 1
rawData = [2, 10, 4, 3, 11, 5, 2, 6, 12, 3, 2]localArea = 2return = [1, 8]For rawData = [2, 10, 4, 3, 11, 5, 2, 6, 12, 3, 2] and localArea = 2, the output should be solution(rawData, localArea) = [1, 8].
Explanation:
rawData[1] = 10 is a local maximum. The remainder of the source explanation is cropped or obscured in the captured image.
Constraints
- FastPrep execution-adapter constraints (not shown in the source image):
rawDatais non-empty.localAreais positive.- Every element of
rawDatais an integer.