Given nums and target, find two indices i < j with nums[i] + nums[j] == target whose positions are closest together (smallest j - i). Return [i, j]. If several pairs are equally close, return the one with the smallest i. Return [] if no pair sums to target.
Examples
Input: nums = [1, 4, 2, 3, 3, 1], target = 6
Output: [1, 2]
Explanation: (4, 2) at [1, 2] and (3, 3) at [3, 4] are both 1 apart; [1, 2] has the smaller i.
Input: nums = [2, 7, 11, 15], target = 9
Output: [0, 1]
Constraints
0 <= len(nums) <= 10**5- Target complexity: O(n) time.
Goals
- Keep only the most recent index of each value
- Minimise a distance with a deterministic tie rule