3835. Count Subarrays With Cost Less Than or Equal to K
You are given an integer array nums, and an integer k. For any subarray nums[l..r], define its cost as: cost = (max(nums[l..r]) - min(nums[l..r])) * (r - l + 1). Return an integer denoting the number of subarrays of nums whose cost is less than or equal to k. Example 1: Input: nums = [1,3,2], k = 4 Output: 5 Explanation: We consider all subarrays of nums: - nums[0..0]: cost = (1 - 1) *
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start