Data Structures & AlgorithmsModerateTCS NQT · Product Company SDE
Problem: In the sorted array [−3, −1, 0, 1, 2, 3], how many pairs of distinct positions (i < j) have a sum of exactly 0?
- A. 3
- B. 2
- C. 1
- D. 4
Correct answer: B. 2
Two pointers from both ends find the pairs (−3, 3) and (−1, 1); the zero element pairs with nothing else, so there are two pairs.
More Coding Interview Problems questions
- Problem: What is C(10, 3) modulo 7?
- Problem: How many prime numbers lie strictly between 100 and 150?
- Problem: The number of decimal digits in 100! is what value?
- Problem: What is gcd(462, 1071)?
- Problem: What is the determinant of the matrix [[2, 1], [1, 3]]?
- Problem: How many permutations of the letters A, B, C, D leave no letter in its original position (for example, A is not in the first…