ProgrammingHardTCS NQT · Infosys
In the sorted array {1, 2, 4, 6, 8, 9}, how many unordered pairs of distinct elements sum to 17?
- A. 2
- B. 3
- C. 4
- D. 1
Correct answer: D. 1
Only (8, 9) sums to 17; 9 needs 8 and every other element needs a partner (above 9) that is not present. A two-pointer scan from both ends finds it in linear time.
More C Programming questions
- What is the largest sum of any three consecutive elements of {2, 1, 5, 1, 3, 2}?
- The sorted array is {1, 3, 6, 6, 8}. What is the index of the first occurrence of 6?
- How many integers in the range 0 to 15 have an even number of 1 bits in binary?
- How many 1 bits are set in 2^20 - 1 (a 32-bit unsigned value)?
- uint8t a = 16; a = a a; What is a?
- uint32t t = 2000000000u + 2000000000u; What is t?