Find Smallest Letter Greater Than Target Problem
Find Smallest Letter Greater Than Target Problem — ExecCode Easy DSA Practice
Solve the Find Smallest Letter Greater Than Target problem on ExecCode. Free online easy DSA practice in Binary Search. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given an array of characters letters that is sorted in non-decreasing order, and a character target. Your task is to compute the required answer and return the smallest character in letters that is lexicographically greater than target. There are at least two different characters in letters. If such a character does not exist, return the first character in letters.
Examples
Input {"letters": ["a", "b", "c", "d", "e"], "target": "c"}; Output d. Input {"letters": ["a", "b", "c", "d", "e"], "target": "e"}; Output a. Input {"letters": ["x", "y", "z"], "target": "w"}; 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.
Practice Find Smallest Letter Greater Than Target free on ExecCode. Browse DSA problems, topic map, and placement guides.