Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Sliding window

Ready to read

JSJavaScript⑂Git◎Interview prepΣDSA in JSSDSystem Design
More topics15›
</>HTML{ }CSS⚛ReactNNext.jsNeNest.jsTSTypeScriptNoNode.js🐳DockerDBSQL & Databases✓Testing🔒Web Security☁Cloud & DevOps◈GraphQL◆Redis☸Kubernetes
☰‹›
Description
All topics›JavaScript›Sliding window

Subarray Product Less Than K

advancedlayer B5 · Sliding window5 tests

Given an array nums of positive integers and an integer k, count how many contiguous subarrays have a product strictly less than k.

  • Subarrays are counted by position, so [1,1] contributes three subarrays: [1], [1], and [1,1]
  • Watch the edge case: when k <= 1 nothing qualifies, because every product of positive integers is at least 1. The answer is 0
  • Target complexity: O(n)

Example: nums = [10,5,2,6], k = 100 gives 8.

Stuck?

All exercisesPlayground
1234567891011121314
loading the editor…

Nothing yet — hit Run and whatever you log shows up here.

Submit to see how you did.

⌘/Ctrl + Enter run⌘/Ctrl + S save⌘/Ctrl + / comment⌘/Ctrl + F find/replace⌘/Ctrl + D select next matchAlt + click multi-cursorTab indent · ⇧Tab outdentEsc leave fullscreen