|
| 1 | +<h2><a href="https://leetcode.com/problems/peak-index-in-a-mountain-array">882. Peak Index in a Mountain Array</a></h2><h3>Medium</h3><hr><p>An array <code>arr</code> is a <strong>mountain</strong> if the following properties hold:</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li><code>arr.length >= 3</code></li> |
| 5 | + <li>There exists some <code>i</code> with <code>0 < i < arr.length - 1</code> such that: |
| 6 | + <ul> |
| 7 | + <li><code>arr[0] < arr[1] < ... < arr[i - 1] < arr[i] </code></li> |
| 8 | + <li><code>arr[i] > arr[i + 1] > ... > arr[arr.length - 1]</code></li> |
| 9 | + </ul> |
| 10 | + </li> |
| 11 | +</ul> |
| 12 | + |
| 13 | +<p>Given a mountain array <code>arr</code>, return the index <code>i</code> such that <code>arr[0] < arr[1] < ... < arr[i - 1] < arr[i] > arr[i + 1] > ... > arr[arr.length - 1]</code>.</p> |
| 14 | + |
| 15 | +<p>You must solve it in <code>O(log(arr.length))</code> time complexity.</p> |
| 16 | + |
| 17 | +<p> </p> |
| 18 | +<p><strong class="example">Example 1:</strong></p> |
| 19 | + |
| 20 | +<pre> |
| 21 | +<strong>Input:</strong> arr = [0,1,0] |
| 22 | +<strong>Output:</strong> 1 |
| 23 | +</pre> |
| 24 | + |
| 25 | +<p><strong class="example">Example 2:</strong></p> |
| 26 | + |
| 27 | +<pre> |
| 28 | +<strong>Input:</strong> arr = [0,2,1,0] |
| 29 | +<strong>Output:</strong> 1 |
| 30 | +</pre> |
| 31 | + |
| 32 | +<p><strong class="example">Example 3:</strong></p> |
| 33 | + |
| 34 | +<pre> |
| 35 | +<strong>Input:</strong> arr = [0,10,5,2] |
| 36 | +<strong>Output:</strong> 1 |
| 37 | +</pre> |
| 38 | + |
| 39 | +<p> </p> |
| 40 | +<p><strong>Constraints:</strong></p> |
| 41 | + |
| 42 | +<ul> |
| 43 | + <li><code>3 <= arr.length <= 10<sup>5</sup></code></li> |
| 44 | + <li><code>0 <= arr[i] <= 10<sup>6</sup></code></li> |
| 45 | + <li><code>arr</code> is <strong>guaranteed</strong> to be a mountain array.</li> |
| 46 | +</ul> |
0 commit comments