Subarray Product Threshold
HardAcc. 75.2%
+50 XP 25
Multiplicative Window
The number of subarrays ending at index right is right - left + 1.
The Assignment
Your function receives nums and k.
- Use sliding window.
- Advance
rightand multiply toproduct. - While
product >= k, divide bynums[left]and advanceleft. - Add the current window size to a
count. - Print the
count.
01EXAMPLE 1
Input
nums=[10, 5, 2, 6], k=100Output
8Explanation: Subarrays: [10], [5], [2], [6], [10,5], [5,2], [2,6], [5,2,6].
Constraints
- O(n) time complexity.
ArraysSliding WindowLogic
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
nums[10,5,2,6]
k100
Expected Output
8
Click RUN to test your solution