Solve Two Sum with a complement map while preserving distinct original indices. Explain duplicate handling, lookup-before-insertion, correctness, and the tradeoff against sorting or pairwise search.
Given an integer array and a target, return the indices of two distinct elements whose sum equals the target.
### Constraints and Clarifications
The report names Two Sum without additional variant details. Use the [official reference](https://leetcode.com/problems/two-sum/description/) for this practice contract: 2 <= n <= 10000, values and target between -1000000000 and 1000000000, and exactly one valid unordered index pair. These are reference-context assumptions, not separately reported interview constraints. Return the two zero-based indices in increasing order as an output-normalization convention. Do not use the same element twice.
### Example
For [4,1,6] and target 10, return [0,2]. For [5,5] and target 10, return [0,1].
### What a Strong Answer Covers
Improve on pairwise enumeration with a lookup map, explain why lookup comes before insertion, preserve original indices, and account for duplicate values.
### Follow-up Questions
- How would the contract change if there were no solution or several valid pairs?
- What tradeoff would a sorting-based approach introduce?
Overview: Solve Two Sum with a complement map while preserving distinct original indices. Explain duplicate handling, lookup-before-insertion, correctness, and the tradeoff against sorting or pairwise search.
Given an integer array and a target, return the indices of two distinct elements whose sum equals the target.
Constraints and Clarifications
The report names Two Sum without additional variant details. Use the official reference for this practice contract: 2 <= n <= 10000, values and target between -1000000000 and 1000000000, and exactly one valid unordered index pair. These are reference-context assumptions, not separately reported interview constraints. Return the two zero-based indices in increasing order as an output-normalization convention. Do not use the same element twice.
Example
For [4,1,6] and target 10, return [0,2]. For [5,5] and target 10, return [0,1].
What a Strong Answer Covers Guidance
Improve on pairwise enumeration with a lookup map, explain why lookup comes before insertion, preserve original indices, and account for duplicate values.
Follow-up Questions Guidance
How would the contract change if there were no solution or several valid pairs?
What tradeoff would a sorting-based approach introduce?