Trains the technique from
LeetCode 373Find K Pairs with Smallest SumsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A test rig couples one damper from the left tray with one damper from the right tray. Tray
contents arrive as left and right, each a list of signed trim values in microns sorted
in non-decreasing order. Trims may be negative.
A coupling picks one position in left and one position in right, and its coupled
trim is the sum of the two values. Positions matter, not values: if a tray holds the same
trim at two positions, each position gives its own coupling.
Return the k couplings whose coupled trim is smallest, each written as
[left trim, right trim]. Order the answer by coupled trim ascending; where two couplings
share a coupled trim, put the smaller left trim first, and if those match too, put the
smaller right trim first. It is guaranteed that k does not exceed the number of couplings.
Example 1
The listed couplings have coupled trims -6, -3, -2 and -1, which are the four smallest, and they appear in ascending order of coupled trim.
Example 2
Coupled trims are 2, 4 and 4. The two couplings that share the trim 4 are ordered by their left trim, so 1 with 3 precedes 3 with 1.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def smallest_coupled_trims(left: list[int], right: list[int], k: int) -> list[list[int]]:public List<List<Integer>> smallestCoupledTrims(int[] left, int[] right, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.