Loading
Loading
A payment reconciler holds a list of transaction amounts and needs to find two of them that sum to a target total.
Return the two positions, smaller index first. Exactly one such pair exists, and a transaction cannot pair with itself.
amounts = [4, 11, 9, 2], target = 13index 0 (4)need 9 — not seen; remember 4index 1 (11)need 2 — not seen; remember 11index 2 (9)need 4 — seen at index 0[0, 2]Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n) time · O(n) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
4 + 9 = 13.
Example 2
Two equal values at different positions are a valid pair.