Subarray Product Less Than K
Updated
Problem statement
You are given an array of positive integers nums and an integer k.
Return the number of contiguous subarrays whose product of all elements is strictly less than k. A subarray is a non-empty run of neighboring elements. Two subarrays at different positions count separately, even if they hold the same values.
Function
numSubarrayProductLessThanK(nums: int[], k: int) → intExamples
Example 1
nums = [2,5,3,10]k = 30return = 6The subarrays with a product less than 30 are [2], [2,5], [5], [5,3], [3], [10]. That is 6 subarrays.
A product equal to 30, as in [2,5,3], does not count, because it is not strictly less than 30.
Example 2
nums = [1,1,1]k = 2return = 6The subarrays with a product less than 2 are [1], [1,1], [1,1,1], [1], [1,1], [1]. That is 6 subarrays.
Example 3
nums = [7,1,7]k = 7return = 1The subarray with a product less than 7 is [1]. That is 1 subarray.
A product equal to 7, as in [7], does not count, because it is not strictly less than 7.
Constraints
1 <= nums.length <= 3 * 10^41 <= nums[i] <= 10000 <= k <= 10^6
More The D.E. Shaw Group interview questions
- IPOPHONE SCREEN · Seen Nov 2026
- Print Numbers in Turn with Three ThreadsPHONE SCREEN · Seen Nov 2026
- Koko Eating BananasPHONE SCREEN · Seen Nov 2026
- Sum of Smallest Non-DivisorsPHONE SCREEN · Seen Nov 2026
- Remove the Fewest Magic BeansPHONE SCREEN · Seen Oct 2026
- Equal-Weight Portfolio VariancePHONE SCREEN · Seen Oct 2026
- Count Distinct Rooted-Tree GraftsPHONE SCREEN · Seen Oct 2026
- Decode WaysPHONE SCREEN · Seen Sep 2026
- Maximum L1 Distance Between Equal-Length SubarraysPHONE SCREEN · Seen Jul 2026
- Count Lucky TicketsOA · Seen Nov 2026
Similar questions at other companies
- Subarray Product Less Than KApple · PHONE SCREENApple interview questions
- Subarray Product Less Than KAngel One · PHONE SCREEN
- Max Consecutive Ones IIINykaa · PHONE SCREENNykaa interview questions
- Max Consecutive Ones IIIAmazon · PHONE SCREEN
- Compact Conversation History by Token BudgetSierra · PHONE SCREENSierra interview questions
- Shortest Window with Required CountsOracle · ONSITE INTERVIEWOracle interview questions
- Count Subarrays With Product Equal to KSalesforce · OASalesforce interview questions
- Longest Binary Window with at Most K OnesLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Count Hotspot Playback WindowsGoogle · ONSITE INTERVIEWGoogle interview questions
- Subarray with a Given SumExpedia · ONSITE INTERVIEWExpedia interview questions