Skip to content

Practice Find Smallest Letter Greater Than Target

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#744
LeetCode Problem

Find Smallest Letter Greater Than Target

Problem Statement

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.

Source: Find Smallest Letter Greater Than Target on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
letters = ["c","f","j"], target = "a"
Output
"c"

# Example 2

Input
letters = ["c","f","j"], target = "c"
Output
"f"

# Example 3

Input
letters = ["x","x","y","y"], target = "z"
Output
"x"

Constraints

2 <= letters.length <= 10^4
letters[i] is a lowercase English letter.
letters is sorted in non-decreasing order.
letters contains at least two different characters.
target is a lowercase English letter.

Related LeetCode Problems

Practice more problems similar to Find Smallest Letter Greater Than Target.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.