β back to unit
Medium
# puzzle gauntlet medium
Closest to the Target
Nobody hit the target number exactly β so the prize goes to the PAIR whose sum lands nearest it. π―
You get the nums (at least two) and the target (exactly one pair-sum is nearest). Print that closest pair-sum.
Example:
Input: nums = [1, 8, 4, 10], target = 13
Output: 12
The pair-sums are 9, 5, 11, 12, 18, 14 β 12 (from 8 + 4) is closest to 13, off by just 1.
π‘ need a hint?
pg-closest-to-target.pyπ given lines are locked β write your code in between
loading...