Two-sum existence
Given an unsorted array and a target, which approach decides in time whether two elements sum to the target?
Show hints (2)+
- You only need existence, not the indices.
- Trade space for time with a set of seen values.
Answer
Reveal answer →Final answer
Single pass with a hash set, checking $\text{target}-x$ — $O(n)$
Want the full step-by-step worked solution? It's part of Premium — along with a worked solution for every question in the bank.
Asked at: Jane Street, Two Sigma