Pick the fix
Which problem fits opposite-end two pointers without extra work?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Find a pair with a given sum in a sorted list
Right: the sum moves predictably as each pointer moves.
Sortedness gives the monotonic behaviour that justifies throwing away one end on every step.
Why not the others?
- B Find a pair with a given sum in an unsorted list. Without order, moving a pointer does not rule anything out; use a hash map or sort first.
- C Find the most frequent value. That is a counting question, not a pointer sweep.