Data Structures & AlgorithmsVery hard

How many contiguous subarrays of [6, 10, 15, 4, 9] have gcd equal to 1?

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

Correct answer: D. 8

The gcd of a subarray depends on every element in it, not just its two endpoints. Taking gcd of the endpoints alone, excluding singletons, or taking the complement each gives a different count.

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

Exams that ask this topic