Show problems as
Classic problem #1EasyArrayHash Table

Two Sum

Real-world version: Ledger Reconciliation
Tracked in this browser only
Read Two Sum on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

Learn the pattern firstTwo Pointers · Arrays, animated step by step

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.

Python
def reconcile_ledger(adjustments: list[int], net: int) -> list[int]:
Java
public int[] reconcileLedger(int[] adjustments, int net)