β back to unit
Medium
# searching medium
Find the Word in the Dictionary
A real dictionary is already alphabetical β nobody reads it front to back! π
You get a SORTED list of words and a target that's definitely inside. Using the split-in-half strategy, print the target's position (from 0).
Example:
Input: words = ["ant", "bee", "cat", "dog", "elk", "fox"], target = "dog"
Output: 3
The middle word "cat" is too early alphabetically, so search the right half; the new middle "elk" is too late, so search the left half β landing on "dog" at position 3.
π‘ need a hint?
srch-dictionary-word.pyπ given lines are locked β write your code in between
loading...