Data Structures & AlgorithmsVery hard

How many index pairs i < j in 1 3 6 5 4 10 2 have A[i] + A[j] equal to a perfect square?

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

Correct answer: D. 4

Test each index pair's sum with an exact square check; the product and difference tests answer different questions, and equal values are not present here so the diagonal case does not matter.

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

Exams that ask this topic