← back to unit
Challenge
# searching advanced
Closest Match
The paint store's sorted shade chart doesn't have your exact color number — take the nearest one. 🎨
You get a SORTED list of nums (at least one) and a target. Print the value closest to the target. If two values tie, print the smaller one.
Example:
Input: nums = [10, 20, 30], target = 24
Output: 20
24 sits between 20 and 30 — comparing distances (4 vs 6), 20 is closer.
💡 need a hint?
srch-closest-match.py🔒 given lines are locked — write your code in between
loading...