Data Structures & AlgorithmsHardGATE CS · ICPC regional

How many contiguous subarrays of [2, 4, 8, 3, 6] have an LCM equal to their maximum element?

  1. A. 10
  2. B. 9
  3. C. 7
  4. D. 12

Correct answer: B. 9

The LCM of a set is at least the maximum, with equality exactly when every element divides the maximum. Checking divisibility by the maximum is a quick test.

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

Exams that ask this topic