Data Structures & AlgorithmsHard

How many contiguous subarrays of [10, 5, 2, 6] have a product strictly less than 100? Every value is a positive integer.

  1. A. 4
  2. B. 9
  3. C. 7
  4. D. 8

Correct answer: D. 8

With positive values the window [left..right] is valid for every start from left to right, so each right end adds right−left+1. Counting one subarray per right end undercounts, and using ≤ instead of < admits the subarray 10·5·2 = 100 that must be excluded.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic