 All Problems
Find Smallest Letter Greater Than Target
easy
binary search
array
google
amazon

You are given an array of characters letters that is sorted in non-decreasing order, and a character target. There are at least two different characters in letters.

Return the smallest character in letters that is lexicographically greater than target. If such a character does not exist, return the first character in letters (circular).

Example 1:

Input: c f j
Target: a
Output: c

Example 2:

Input: c f j
Target: c
Output: f

Example 3:

Input: c f j
Target: j
Output: c

Input format: First line: space-separated characters. Second line: target character.

Output format: The smallest character strictly greater than target (wraps around).

Run to check your code against the sample cases, or submit to run every case