Implement two-pointer unique-pair sum search
CitadelData Scientist · Technical ScreenLast updated
Implement two-pointer unique-pair sum search evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
Given a nondecreasing integer array nums and an integer target, return all unique value pairs [a, b] with a <= b such that a + b == target. Use the two-pointer technique to achieve O(n) time and O(
- extra space beyond the output, and ensure duplicates in nums do not produce duplicate pairs. Additionally: a) Describe how you would return indices instead of values and any implications for stability. b) Explain how you would adapt the method if nums arrives as a stream that cannot be fully stored in memory. c) Analyze time and space complexity.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.