Baseline Binary Search · 1D Arrays O(log n) · O(1)
A structural sensor logs one load value per segment along a beam, and inspection must sample the most stressed segment - one whose load strictly exceeds both neighbours. Segments beyond the beam's ends are treated as carrying no load, so a segment only needs to beat the neighbours that exist. Any crest qualifies when several exist.
Input: An array nums of n integers.
Output: The index of any element strictly greater than its neighbours, where out-of-array neighbours count as negative infinity.
1 <= n <= 1000-2^31 <= nums[i] <= 2^31 - 1nums[i] != nums[i + 1] for every valid iAn O(log n) algorithm is requiredInput: {"nums":[1,2,3,1]}
Output: 2
The load rises to 3 at index 2 and drops afterwards, making that segment the crest.
Input: {"nums":[1,2,1,3,5,6,4]}
Output: 5
Two crests exist (index 1 and index 5) and either is a correct answer; this profile reports 5.