← back to unit
Medium
# searching medium
Binary Search a Sorted List of Prices
The vending machine's sorted price list is taped to its side. 🥤
You get the SORTED prices and the exact coins you're holding. Print exact match if some item costs exactly that, otherwise no match — by splitting the list, not scanning it.
Example:
Input: prices = [25, 50, 75, 100, 150], coins = 75
Output: exact match
Splitting the range in half repeatedly narrows the search straight down to 75.
💡 need a hint?
srch-sorted-prices.py🔒 given lines are locked — write your code in between
loading...