Skip to content

Practice Count Non-Decreasing Subarrays After K Operations

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#3420
LeetCode Problem

Count Non-Decreasing Subarrays After K Operations

Problem Statement

You are given an array nums of n integers and an integer k. For each subarray of nums, you can apply up to k operations on it. In each operation, you increment any element of the subarray by 1. Note that each subarray is considered independently, meaning changes made to one subarray do not persist to another. Return the number of subarrays that you can make non-decreasing ​​​​​after performing at most k operations. An array is said to be non-decreasing if each element is greater than or equal to its previous element, if it exists.

Source: Count Non-Decreasing Subarrays After K Operations on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [6,3,1,2,4,4], k = 7
Output
17

# Example 2

Input
nums = [6,3,1,3,6], k = 4
Output
12

Constraints

1 <= nums.length <= 10^5
1 <= nums[i] <= 10^9
1 <= k <= 10^9

Related LeetCode Problems

Practice more problems similar to Count Non-Decreasing Subarrays After K Operations.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.