Loading problem...
You are given an integer array called a unimodal sequence of length n. A unimodal sequence has a unique characteristic: the values strictly increase up to a single maximum point (the summit), and then strictly decrease from that point onward.
The summit is defined as the element that is greater than all other elements in the sequence. There is exactly one summit in the array.
Your task is to identify and return the index of the summit element.
Important: Your solution must achieve a time complexity of O(log n). A linear scan through the entire array is not acceptable.
sequence = [0,1,0]1The sequence rises from 0 to 1, then falls back to 0. The summit is at index 1 with value 1.
sequence = [0,2,1,0]1Starting at 0, the sequence increases to 2 (the maximum), then decreases through 1 to 0. The summit at index 1 has value 2.
sequence = [0,10,5,2]1The sequence rises from 0 to 10, then strictly decreases through 5 and 2. Index 1 holds the summit value of 10.
Constraints