Smallest Letter Greater Than Target
L5 Medium Binary Search
Binary search works on any ordered sequence; characters are no exception. For wrapping sequences, if no match is found, the answer wraps to the first element.
Given a string letters of sorted lowercase letters (duplicates allowed) and a single-character target, return the smallest character in letters that is strictly greater than target. If none exists, wrap around and return the first character.
Examples
▸ letters = "cfj", target = "a"
→ c
▸ letters = "cfj", target = "c"
→ f
▸ letters = "xxyy", target = "z"
→ x