ProgrammingHardTCS CodeVita · Infosys HackWithInfy
Which statement about counting pairs i < j with a[i] + a[j] == t is FALSE?
- A. A dictionary of earlier values finds the count in O(n) on average
- B. A double loop over all pairs is O(n^2) and too slow for n = 2 x 10^5
- C. Sorting and moving both pointers after each match skips repeated values and undercounts
- 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
- What is printed? python a = [] for i in range(20): a.append(i) print(len(a), a[-1], a.pop(), len(a))
- What is printed? python print(int('0012'), int('ff', 16), int('0b11', 0), int('1234'))
- What is printed? python print(-7 // 2, -7 % 2, 7 // -2, 7 % -2, divmod(-7, 2))
- What is printed? python print(round(0.5), round(1.5), round(2.5), round(-0.5), round(2.675, 2))
- What is printed? python s = 'aaaa' print(s.count('aa'), s.replace('aa', 'b'), 'a,,b'.split(','), ' x y '.split(' '))
- What is printed? python import itertools print([''.join(p) for p in itertools.permutations('abc', 2)][:4])