3187. Peaks in Array Hard
1/**
2 * [3187] Peaks in Array
3 *
4 * A peak in an array arr is an element that is greater than its previous and next element in arr.
5 * You are given an integer array nums and a 2D integer array queries.
6 * You have to process queries of two types:
7 *
8 * queries[i] = [1, li, ri], determine the count of peak elements in the <span data-keyword="subarray">subarray</span> nums[li..ri].<!-- notionvc: 73b20b7c-e1ab-4dac-86d0-13761094a9ae -->
9 * queries[i] = [2, indexi, vali], change nums[indexi] to <font face="monospace">vali</font>.
10 *
11 * Return an array answer containing the results of the queries of the first type in order.<!-- notionvc: a9ccef22-4061-4b5a-b4cc-a2b2a0e12f30 -->
12 * Notes:
13 *
14 * The first and the last element of an array or a subarray<!-- notionvc: fcffef72-deb5-47cb-8719-3a3790102f73 --> cannot be a peak.
15 *
16 *
17 * <strong class="example">Example 1:
18 * <div class="example-block">
19 * Input: <span class="example-io">nums = [3,1,4,2,5], queries = [[2,3,4],[1,0,4]]</span>
20 * Output: <span class="example-io">[0]</span>
21 * Explanation:
22 * First query: We change nums[3] to 4 and nums becomes [3,1,4,4,5].
23 * Second query: The number of peaks in the [3,1,4,4,5] is 0.
24 * </div>
25 * <strong class="example">Example 2:
26 * <div class="example-block">
27 * Input: <span class="example-io">nums = [4,1,4,2,1,5], queries = [[2,2,4],[1,0,2],[1,0,4]]</span>
28 * Output: <span class="example-io">[0,1]</span>
29 * Explanation:
30 * First query: nums[2] should become 4, but it is already set to 4.
31 * Second query: The number of peaks in the [4,1,4] is 0.
32 * Third query: The second 4 is a peak in the [4,1,4,2,1].
33 * </div>
34 *
35 * Constraints:
36 *
37 * 3 <= nums.length <= 10^5
38 * 1 <= nums[i] <= 10^5
39 * 1 <= queries.length <= 10^5
40 * queries[i][0] == 1 or queries[i][0] == 2
41 * For all i that:
42 *
43 * queries[i][0] == 1: 0 <= queries[i][1] <= queries[i][2] <= nums.length - 1
44 * queries[i][0] == 2: 0 <= queries[i][1] <= nums.length - 1, 1 <= queries[i][2] <= 10^5
45 *
46 *
47 *
48 */
49pub struct Solution {}
50
51// problem: https://leetcode.com/problems/peaks-in-array/
52// discuss: https://leetcode.com/problems/peaks-in-array/discuss/?currentPage=1&orderBy=most_votes&query=
53
54// submission codes start here
55
56impl Solution {
57 pub fn count_of_peaks(nums: Vec<i32>, queries: Vec<Vec<i32>>) -> Vec<i32> {
58 vec![]
59 }
60}
61
62// submission codes end
63
64#[cfg(test)]
65mod tests {
66 use super::*;
67
68 #[test]
69 fn test_3187() {
70 }
71}
72
Back
© 2025 bowen.ge All Rights Reserved.