Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

How many contiguous subarrays of [10, 5, 2, 6] have a product strictly less than 100?

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

Correct answer: D. 8

Sliding window: shrink from the left while the product is at least 100 and add the window length per right end: 1 + 2 + 2 + 3 = 8. Shrinking only when the product exceeds 100 keeps [10, 5, 2] = 100 and gives 9; 4 counts single elements and 3 only pairs.

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

Exams that ask this topic