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

Subarray Product Less Than K

The D.E. Shaw Group logoThe D.E. Shaw Group● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: In a long D. E. Shaw round with two coding questions, a concurrency question and a Java question, the first coding question was a variation of Subarray Product Less Than K.

The report does not say what the variation changed, and it gives no examples or limits. Here you get the usual version: count the contiguous subarrays of positive numbers whose product is strictly less than k. The limits are added for our version.

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

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

Examples

Example 1

nums = [2,5,3,10]k = 30return = 6

The 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 = 6

The 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 = 1

The 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^4
  • 1 <= nums[i] <= 1000
  • 0 <= 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
All The D.E. Shaw Group interview questionsSee The D.E. Shaw Group hiring insights
Saved
class Solution {
    public int numSubarrayProductLessThanK(int[] nums, int k) {
        // Write your code here.
    }
}
Checking account…