
Clarify and plan
Read the prompt and examples in Clarify. Use Plan to write a baseline, the key invariant, and a tricky input in Scratchpad.
ExampleFor [3, 3] with target 6, return [0, 1]. Store earlier values and their indices. Check for the complement before adding the current value so you cannot pair it with itself.
Implement and test
Use Code to edit the starter function. Use Run to execute visible tests and inspect Results. Iterate on a failing case before submitting.
ExampleTrace [3, 2, 4] with target 6. At index 2, the complement of 4 is 2, which was seen at index 1. Expect [1, 2].
Explain your approach
Use Complexity to enter time and space claims with reasoning. In Communicate, write a short explanation you could say aloud.
ExampleExpected O(n) time with constant average map operations, and O(n) auxiliary space because the map can hold a value from each input position.
Submit and reflect
Open Submit in the workflow bar, review the readiness checklist, and choose Submit Solution. Read the Attempt Debrief and save a reflection with a next review action.
ExampleIf correctness passes but your explanation is incomplete, write a 30-second explanation of why the map only contains earlier indices and rehearse it on the next attempt.
Check your work
Your submission has a formal result, and your reflection names one specific change for the next attempt.
Try it yourself
After your Two Sum submission, use a new solution draft for the nested-loop baseline. Run both versions on [[3, 3], 6] and [[3, 2, 4], 6]. Keep the original draft for comparison.
- What to look for
- Both versions should return the same indices. Explain why a pair scan can inspect about n²/2 pairs while a map trades extra memory for a single pass.