Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Subarray Product Less Than K

Medium
sliding-windowarraytwo-pointers

Given an array of positive integers and an integer k, count the number of contiguous subarrays whose product is strictly less than k.

Input

  • Line 1: space-separated positive integers
  • Line 2: the integer k

Output: the count of qualifying subarrays.

Example 1
Input:
10 5 2 6
100
Output:
8

[10], [5], [2], [6], [10 5], [5 2], [2 6], [5 2 6].

Example 2
Input:
1 2 3
0
Output:
0

Constraints

  • 1 ≤ nums.length ≤ 3·10^4
  • 1 ≤ nums[i] ≤ 1000
  • 0 ≤ k ≤ 10^6
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.