Data Structures & AlgorithmsModerateTCS NQT · two pointers
Problem: What property of an array makes the two-pointer technique for pair sums valid?
- A. The array has no duplicates
- B. The array is sorted
- C. The array is a permutation
- D. The array is positive
Correct answer: B. The array is sorted
On a sorted array, moving the left or right pointer changes the sum monotonically, which lets the search skip values.
More Coding Interview Problems questions
- Problem: What is the purpose of a 'segment tree beats' structure?
- Problem: What is the number of comparisons needed in the worst case to check whether a sorted array of n elements contains a given value…
- Problem: What is the greedy choice used in the 'minimum number of arrows to burst balloons' problem?
- Problem: Which problem is solved by the Gale-Shapley algorithm in O(n^2) time with preference lists?
- Problem: Which data structure supports adding a value to a prefix of an array and finding the first index whose value is at least x, each…
- Problem: What is the time complexity of computing the diameter of a tree with n vertices by two breadth-first searches?