Tap here to switch tabs
Problem
Submissions

Problem: Find Smallest Letter Greater Than Target

Try to solve the Find Smallest Letter Greater Than Target problem.

Statement

You are given an array of characters letters sorted in non-decreasing order, and a character target. There are at least 22 distinct characters in letters.

Return the smallest character in letters that is lexicographically strictly greater than target. If no such character exists, return the first character in letters.

Note: The letters wrap around. If target is greater than or equal to all characters in letters, the answer is the first character of the array.

Constraints:

  • 2≤2 \leq letters.length ≤104\leq 10^4

  • letters[i] is a lowercase English letter.

  • letters is sorted in non-decreasing order.

  • letters contains at least 22 different characters.

  • target is a lowercase English letter.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find Smallest Letter Greater Than Target

Try to solve the Find Smallest Letter Greater Than Target problem.

Statement

You are given an array of characters letters sorted in non-decreasing order, and a character target. There are at least 22 distinct characters in letters.

Return the smallest character in letters that is lexicographically strictly greater than target. If no such character exists, return the first character in letters.

Note: The letters wrap around. If target is greater than or equal to all characters in letters, the answer is the first character of the array.

Constraints:

  • 2≤2 \leq letters.length ≤104\leq 10^4

  • letters[i] is a lowercase English letter.

  • letters is sorted in non-decreasing order.

  • letters contains at least 22 different characters.

  • target is a lowercase English letter.