Data Structures & AlgorithmsModerateGATE CS · TCS NQT

How many contiguous subarrays of [2, 8, 3, 3, 2, 6] have a product that is a perfect square?

  1. A. 6
  2. B. 4
  3. C. 7
  4. D. 5

Correct answer: D. 5

A product is a square exactly when every prime appears to an even power, so track the parity vector of square-free parts instead of multiplying out the values.

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

Exams that ask this topic