#3835
Count Subarrays With Cost Less Than or Equal to K
specialist · 940 · lc medium +32 · 45.5% accepted · 144 likes · top 29%
Description
Given an integer array nums and an integer k, define the cost of a subarray nums[l..r] as (max(nums[l..r]) - min(nums[l..r])) * (r - l + 1). Count and return the number of subarrays whose cost does not exceed k.
Code
1
2
3