2302. Count Subarrays With Score Less Than K
The score of an array is defined as the product of its sum and its length.
- For example, the score of [1, 2, 3, 4, 5] is (1 + 2 + 3 + 4 + 5) * 5 = 75.
Given a positive integer array nums and an integer k, return the number of non-empty subarrays of nums whose score is strictly less than k.
A subarray is a contiguous sequence of elements within an array.
- two pointer solution
- Time : O(n)
- Space : O(n)
c++
1 | class Solution { |
- binary search solution
- Time : O(nlogn)
- Space : O(n)
c++
1 | class Solution { |