← back to unit
Medium
# searching medium
Binary Search a Sorted List of Ages
The village registry lists every resident's age in sorted order, all different. 🏘️
You get the SORTED ages and a target age that's definitely present. Print its position (from 0) using the split-in-half strategy.
Example:
Input: ages = [7, 12, 19, 25, 31, 44], target = 25
Output: 3
Splitting the range in half repeatedly narrows the search down to age 25, which sits at position 3.
💡 need a hint?
srch-sorted-ages.py🔒 given lines are locked — write your code in between
loading...