Practice Peaks in Array
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
A peak is strictly greater than both adjacent elements. Process queries on nums in order: [1, l, r] asks for the number of peaks in the inclusive subarray nums[l..r], while [2, index, value] replaces nums[index] with value. The endpoints of a queried subarray cannot be peaks. Return the counts for type-1 queries in order.
Source: Peaks in Array on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [3,1,4,2,5], queries = [[2,3,4],[1,0,4]]
Output
[0]
# Example 2
Input
nums = [4,1,4,2,1,5], queries = [[2,2,4],[1,0,2],[1,0,4]]
Output
[0,1]
Constraints
3 <= nums.length <= 10^5
1 <= nums[i] <= 10^5
1 <= queries.length <= 10^5
queries[i][0] == 1 or queries[i][0] == 2
For all i that:
queries[i][0] == 1: 0 <= queries[i][1] <= queries[i][2] <= nums.length - 1
queries[i][0] == 2: 0 <= queries[i][1] <= nums.length - 1, 1 <= queries[i][2] <= 10^5
queries[i][0] == 1: 0 <= queries[i][1] <= queries[i][2] <= nums.length - 1
queries[i][0] == 2: 0 <= queries[i][1] <= nums.length - 1, 1 <= queries[i][2] <= 10^5
Related LeetCode Problems
Practice more problems similar to Peaks in Array.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.