852. Peak Index in a Mountain Array Medium
1/**
2 * [852] Peak Index in a Mountain Array
3 *
4 * An array arr a mountain if the following properties hold:
5 *
6 * arr.length >= 3
7 * There exists some i with 0 < i < arr.length - 1 such that:
8 *
9 * arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
10 * arr[i] > arr[i + 1] > ... > arr[arr.length - 1]
11 *
12 *
13 *
14 * Given a mountain array arr, return the index i such that arr[0] < arr[1] < ... < arr[i - 1] < arr[i] > arr[i + 1] > ... > arr[arr.length - 1].
15 * You must solve it in O(log(arr.length)) time complexity.
16 *
17 * Example 1:
18 *
19 * Input: arr = [0,1,0]
20 * Output: 1
21 *
22 * Example 2:
23 *
24 * Input: arr = [0,2,1,0]
25 * Output: 1
26 *
27 * Example 3:
28 *
29 * Input: arr = [0,10,5,2]
30 * Output: 1
31 *
32 *
33 * Constraints:
34 *
35 * 3 <= arr.length <= 10^5
36 * 0 <= arr[i] <= 10^6
37 * arr is guaranteed to be a mountain array.
38 *
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/peak-index-in-a-mountain-array/
43// discuss: https://leetcode.com/problems/peak-index-in-a-mountain-array/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48 pub fn peak_index_in_mountain_array(arr: Vec<i32>) -> i32 {
49 0
50 }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn test_852() {
61 }
62}
63
Back
© 2025 bowen.ge All Rights Reserved.