FastPrepSubarray Product Less Than K
Problems/Subarray Product Less Than K

Subarray Product Less Than K

Apple logoApple● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Apple asked this in a technical phone screen for an IS&T team, written on an online coding tool without running it. The first question was the well-known subarray-product-less-than-k problem, named by its number. Two follow-ups asked how to change the solution to count subarrays whose product equals k, and to print every qualifying subarray from the first question.

The report gave no limits or examples. Here, the task is the first question in its well-known public version, with up to 3 * 10^4 values from 1 to 1000 and k up to 10^6. The two follow-ups are covered in the editorial as discussion.

Our version is about 70% the same as the reported question.

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) → int

Examples

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 * 104
  • 1 <= nums[i] <= 1000
  • 0 <= 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

Interview reports that mention this question

  • Apple SWE Phone Screen: Subarray Products: 1 Experience

Apple interview experiences

  • Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
  • Apple AI Coding and Related Interviews: 17 Experiences
  • Apple India SWE New Grad Interviews: 5 Experiences
  • Apple New Grad SWE Phone Screens: 12 Experiences (Part 3 of 3)
  • Apple New Grad SWE and Embedded: 16 Experiences (Part 2 of 3)
All Apple interview questionsSee Apple hiring insights
Saved
class Solution {
    public int numSubarrayProductLessThanK(int[] nums, int k) {
        // Write your code here.
    }
}
Checking account…