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.

  1. Use sliding window.
  2. Advance right and multiply to product.
  3. While product >= k, divide by nums[left] and advance left.
  4. Add the current window size to a count.
  5. Print the count.

01EXAMPLE 1

Inputnums=[10, 5, 2, 6], k=100
Output8

Explanation: Subarrays: [10], [5], [2], [6], [10,5], [5,2], [2,6], [5,2,6].

Constraints

  • O(n) time complexity.
ArraysSliding WindowLogic
JavaScript
Loading...
1 Hidden

Input Arguments

nums[10,5,2,6]
k100

Expected Output

8

Click RUN to test your solution