Skip to content

Commit 51e1e2e

Browse files
committed
Apr 28
1 parent a362b0c commit 51e1e2e

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution:
2+
def countSubarrays(self, nums: list[int], k: int) -> int:
3+
ptr1, curr_sum, count = 0, 0, 0
4+
for ptr2 in range(len(nums)):
5+
curr_sum += nums[ptr2]
6+
while curr_sum * (ptr2 - ptr1 + 1) >= k:
7+
curr_sum -= nums[ptr1]
8+
ptr1 += 1
9+
count += (ptr2 - ptr1 + 1)
10+
return count
11+
12+
13+
def main():
14+
nums = [2, 1, 4, 3, 5]
15+
k = 10
16+
assert Solution().countSubarrays(nums, k) == 6
17+
18+
nums = [1, 1, 1]
19+
k = 5
20+
assert Solution().countSubarrays(nums, k) == 5
21+
22+
23+
if __name__ == '__main__':
24+
main()

2025-04-April-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
| April 25 | [2845. Count of Interesting Subarrays](https://leetcode.com/problems/count-of-interesting-subarrays/) | Medium | Unsolved |
3232
| April 26 | [2444. Count Subarrays With Fixed Bounds](https://leetcode.com/problems/count-subarrays-with-fixed-bounds/) | Hard | Unsolved |
3333
| April 27 | [3392. Count Subarrays of Length Three With a Condition](https://leetcode.com/problems/count-subarrays-of-length-three-with-a-condition/) | Easy | Solved |
34-
| April 28 | []() | | |
34+
| April 28 | [2302. Count Subarrays With Score Less Than K](https://leetcode.com/problems/count-subarrays-with-score-less-than-k/) | Hard | Solved |
3535
| April 29 | []() | | |
3636
| April 30 | []() | | |
3737

@@ -41,4 +41,4 @@
4141
| --- | --- | --- | --- |
4242
| Easy | 8 | 8 | 0 |
4343
| Medium | 13 | 9 | 4 |
44-
| Hard | 5 | 0 | 5 |
44+
| Hard | 6 | 1 | 5 |

0 commit comments

Comments
 (0)