The Target Hunt

Given a list of integers and integer target, return all unique [x, y] pairs with x != y (from distinct indices) summing to target, each index used in at most one pair. Preserve discovery order (greedy: sweep left-to-right, for each x pick the smallest index y > x such that x+y = target and y is unclaimed). Return pairs as lists.

Example

Input
nums:[2,4,3,5,7,8,1]
target:9
Output
[[2,7],[4,5],[8,1]]