The Question
CodingSubarray Product Less Than K
Given an array of positive 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.
Constraints:
- 1 <= nums.length <= 3 * 10^4
- 1 <= nums[i] <= 1000
- 0 <= k <= 10^6
Example:
Input: nums = [10, 5, 2, 6], k = 100
Output: 8
Explanation: The 8 subarrays are: [10], [5], [2], [6], [10, 5], [5, 2], [2, 6], [5, 2, 6]. Note that [10, 5, 2] is not included as its product is 100, which is not strictly less than k.Java
Sliding Window
Two Pointers