Sliding Window Variable Subarrays Shorter¶
Table of Contents¶
- 713. Subarray Product Less Than K (Medium)
- 3258. Count Substrings That Satisfy K-Constraint I (Easy)
- 2302. Count Subarrays With Score Less Than K (Hard)
- 2762. Continuous Subarrays (Medium)
- 3134. Find the Median of the Uniqueness Array (Hard)
- 3261. Count Substrings That Satisfy K-Constraint II (Hard)
- 2743. Count Substrings Without Repeating Character (Medium) 👑
713. Subarray Product Less Than K¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, binary search, sliding window, prefix sum
713. Subarray Product Less Than K - Python Solution
from typing import List
# Sliding window - Fixed
def numSubarrayProductLessThanK(nums: List[int], k: int) -> int:
if k <= 1:
return 0
left = 0
product = 1
count = 0
for right in range(len(nums)):
product *= nums[right]
while product >= k:
product //= nums[left]
left += 1
count += right - left + 1
return count
nums = [10, 5, 2, 6]
k = 100
print(numSubarrayProductLessThanK(nums, k)) # 8
3258. Count Substrings That Satisfy K-Constraint I¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: string, sliding window
2302. Count Subarrays With Score Less Than K¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, binary search, sliding window, prefix sum
2762. Continuous Subarrays¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, queue, sliding window, heap priority queue, ordered set, monotonic queue
3134. Find the Median of the Uniqueness Array¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, hash table, binary search, sliding window
3261. Count Substrings That Satisfy K-Constraint II¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, string, binary search, sliding window, prefix sum
2743. Count Substrings Without Repeating Character¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: hash table, string, sliding window