Given an array of temperature readings, return the indices of all peak temperature readings. A peak temperature reading is an element which is not smaller than its neighbors. If no such readings exist, return an empty array.
Explanation: Step-by-step: with input [1, 3, 2, 1], we first compare each element with its neighbors. The element at index 1 (value 3) is greater than its neighbors (1 and 2), so it is a peak temperature reading. The output is [1], which is the index of the peak temperature reading.
Explanation: Step-by-step: with input [1, 2, 3, 4, 5], we first compare each element with its neighbors. The element at index 0 (value 1) is less than its neighbor (2), but since it's the first element, it's only compared with the next one. The element at index 4 (value 5) is greater than its neighbor (4), so it is a peak temperature reading. Additionally, the first element is also considered a peak if it's greater than or equal to its only neighbor, but in this case, it's not. However, considering the definition of a peak in the context of this problem, the first and last elements should be considered peaks if they are greater than or equal to their single neighbor. Thus, the output is [0, 4], which are the indices of the peak temperature readings.
Master coding challenges related to Arrays and solve the [Backup] Temperature Sensor Analysis problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak