Standard Bar Arrays · Medium O(n) · O(n)
A reconciliation job receives one batch of transaction amounts and a settlement figure, and exactly one pair of amounts in the batch adds up to that figure. Auditors need the positions of the two entries rather than their values. Each entry may be used at most once, and the pair may be reported in any order.
Input: An array nums of n integers and an integer target.
Output: Two distinct 0-indexed positions i and j with i != j such that nums[i] + nums[j] == target, in any order.
2 <= n <= 10^4-10^9 <= nums[i] <= 10^9-10^9 <= target <= 10^9Exactly one valid pair existsInput: {"nums":[2,7,11,15],"target":9}
Output: [0,1]
Positions 0 and 1 hold 2 and 7, which sum to the settlement figure 9.
Input: {"nums":[3,2,4],"target":6}
Output: [1,2]
The matching entries sit at positions 1 and 2; the leading 3 is not part of the pair.