Started with the brute force nested loop thing because my brain just goes there first.
Start by clarifying the problem constraints (e.g., exactly one solution, cannot use same element twice) and discussing brute force O(n^2) as a baseline. Then introduce a hash map to store each number's complement and index, achieving O(n) time and O(n) space. Walk through a concrete example to demonstrate correctness and edge cases.
Pro tip: Mention that the hash map approach trades space for time, and if the array is sorted, a two-pointer approach could achieve O(n) time with O(1) space—showing you consider trade-offs. Also, explicitly state that you assume exactly one solution exists, as per common problem statements.
Ask if there is exactly one solution, if the same element can be used twice, and if the array is sorted. Confirm input/output types and edge cases like empty array or no solution.
Explain the naive O(n^2) approach using nested loops to check all pairs. This sets a baseline and shows you can analyze time complexity.
Iterate through the array once, storing each number and its index in a hash map. For each element, check if its complement (target - current) exists in the map; if so, return the indices.
Use a small example like [2,7,11,15] with target 9 to show how the hash map works. Mention edge cases: duplicate numbers, negative numbers, and ensuring indices are distinct.
State that time complexity is O(n) and space complexity is O(n). Optionally mention that if the array is sorted, a two-pointer approach uses O(1) space, but sorting would take O(n log n).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.