Two Sum
Real-world version: Ledger ReconciliationThe statement here is our own: the same inputs, outputs and technique.
An accountant is closing out a ledger. You are given an integer array adjustments, where each entry is a signed correction applied to an account, and an integer net.
Exactly one pair of entries sums to net. Return the indices of those two entries, in any order. An entry cannot be paired with itself.
Examples
Example 1
- Input
- adjustments = [7, -3, 11, 2], net = 8
- Output
- [1, 2]
The entry at index 1 holds -3 and the entry at index 2 holds 11, which together settle to 8.
Example 2
- Input
- adjustments = [-5, -5, 4], net = -10
- Output
- [0, 1]
Both entries hold the same amount but occupy separate positions, so pairing them is allowed.
Example 3
- Input
- adjustments = [6, 1], net = 7
- Output
- [0, 1]
With only two entries available, they must be the settling pair.
Constraints
- 2 <= adjustments.length <= 10^4
- -10^9 <= adjustments[i] <= 10^9
- -10^9 <= net <= 10^9
- Exactly one valid pair exists
The values you return may be in any order.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def reconcile_ledger(adjustments: list[int], net: int) -> list[int]:public int[] reconcileLedger(int[] adjustments, int net)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 8 test cases: 8 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's