ProgrammingHardTCS CodeVita · Infosys HackWithInfy

Which statement about counting pairs i < j with a[i] + a[j] == t is FALSE?

  1. A. A dictionary of earlier values finds the count in O(n) on average
  2. B. A double loop over all pairs is O(n^2) and too slow for n = 2 x 10^5
  3. C. Sorting and moving both pointers after each match skips repeated values and undercounts
  4. D. Sorting and moving both pointers after each match gives the exact count even with duplicates

Correct answer: D. Sorting and moving both pointers after each match gives the exact count even with duplicates

Moving both pointers after a match skips the other copies of the same value, so the count is wrong when duplicates exist. The other three statements are true.

More Python Programming questions

Exams that ask this topic