Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

How many non-empty contiguous subarrays of [1, 3, 6, 10, 2, 6] have a sum that is a perfect square (including 1, 4, 9, ...)?

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

Correct answer: C. 4

Check every subarray sum with an exact integer square-root test; the count of perfect-square sums is 4. Float square roots can misjudge large values, so the integer test matters.

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

Exams that ask this topic