Z16
Subarray Product Less Than K
Problem Statement & Objective
Given an array of integers nums and an integer k, return the number of contiguous subarrays where the product of all the elements in the subarray is strictly less than k.
Function Signature (Python)
subarray_product_less_than_k(nums: list[int], k: int) -> intInput & Output Contract
Output Rule:Count of contiguous subarrays with product < k.
System Constraints
1 <= nums.length <= 3 * 10^4
1 <= nums[i] <= 1000
0 <= k <= 10^6Example Execution Walkthrough
nums = [10, 5, 2, 6], k = 100
subarrays: [10], [5], [2], [6], [10, 5], [5, 2], [2, 6], [5, 2, 6] -> result 8Example Test Scenarios (3)
Example 1
Input:
[[10,5,2,6],100]Expected Output:
8Example 2: k=0
Input:
[[1,2,3],0]Expected Output:
0Example 3: Birler
Input:
[[1,1,1],2]Expected Output:
6