Subarray Product Less Than K
Updated
Problem statement
Given an array of 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.
Function
numSubarrayProductLessThanK(nums: int[], k: int) → intExamples
Example 1
nums = [10,5,2,6]k = 100return = 8- The 8 subarrays with product below 100 are
[10],[5],[2],[6],[10, 5],[5, 2],[2, 6]and[5, 2, 6]. [10, 5, 2]has product 100, which is not strictly less than 100.
Example 2
nums = [1,2,3]k = 0return = 0- Every product is at least 1, so none is below 0.
Constraints
1 <= nums.length <= 3 * 1041 <= nums[i] <= 10000 <= k <= 106
More Apple Phone Screen questions
- Evaluate DivisionPHONE SCREEN · Seen Nov 2026
- Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
- Validate a BST with a Custom ComparisonPHONE SCREEN · Seen Nov 2026
- Design a Food Rating SystemPHONE SCREEN · Seen Oct 2026
- Days Until Poisoned Plants StabilizePHONE SCREEN · Seen Oct 2026
- Capture Surrounded Regions with Union-FindPHONE SCREEN · Seen Oct 2026
- Maintain a Consistent-Hashing RingPHONE SCREEN · Seen Oct 2026
- Count Nodes in a ChainPHONE SCREEN · Seen Oct 2026
- Run-Length DecodingPHONE SCREEN · Seen Oct 2026
- Implement Hit CounterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Subarray Product Less Than KAngel One · PHONE SCREEN
- Subarray Product Less Than KThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
- 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