Given a sorted array of temperatures, find the index of the peak temperature. The temperatures are either increasing and then decreasing, or vice versa, around a single peak temperature.
Explanation: Step-by-step: with input [7, 7, 8, 7, 7], we first check if the array is increasing or decreasing. Since it's increasing, we then check if the last element is the peak. If it is, we return the last index. Otherwise, we return the index of the peak element in the increasing part of the array.
Explanation: Step-by-step: with input [7, 8, 7, 7, 7], we first check if the array is increasing or decreasing. Since it's decreasing, we then check if the first element is the peak. If it is, we return the first index. Otherwise, we return the index of the peak element in the decreasing part of the array.
Master coding challenges related to Arrays and solve the [Backup] Galaxy Temperature Peaks problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak