Find the Next Strictly Larger Letter with Wraparound

Quick Overview

Find the Next Strictly Larger Letter with Wraparound. letters is sorted in nondecreasing order. Return its smallest letter strictly after target alphabetically.

Find the Next Strictly Larger Letter with Wraparound

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem letters is sorted in nondecreasing order. Return its smallest letter strictly after target alphabetically. If none is larger, wrap to letters[0]. Duplicates may occur. ```cpp class Solution { public: char nextGreatestLetter(vector<char>& letters, char target); }; ``` ### Examples **Example 1:** ```text letters = ["b","d","d","h"], target = "d" Output: "h" Explanation: Equal d entries are skipped. ``` **Example 2:** ```text letters = ["b","d"], target = "z" Output: "b" Explanation: No entry is larger, so wrap to the first. ``` ### Constraints - Array length is 2 through 10000, with at least two distinct characters. - Entries and target are lowercase English letters. - Array order is nondecreasing. ### Contract considerations Preserve strict comparison and wraparound. ```hint Read the boundary condition Where is the first true value of letters[i]>target? ``` ### Boundary reminders Preserve strict comparison and wraparound.

Overview: Find the Next Strictly Larger Letter with Wraparound. letters is sorted in nondecreasing order. Return its smallest letter strictly after target alphabetically.

Google logo
Google
Source window: 0–6 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

letters is sorted in nondecreasing order. Return its smallest letter strictly after target alphabetically. If none is larger, wrap to letters[0]. Duplicates may occur.

class Solution {
public:
    char nextGreatestLetter(vector<char>& letters, char target);
};

Examples

Example 1:

letters = ["b","d","d","h"], target = "d"
Output: "h"
Explanation: Equal d entries are skipped.

Example 2:

letters = ["b","d"], target = "z"
Output: "b"
Explanation: No entry is larger, so wrap to the first.

Constraints

  • Array length is 2 through 10000, with at least two distinct characters.
  • Entries and target are lowercase English letters.
  • Array order is nondecreasing.

Contract considerations

Preserve strict comparison and wraparound.

Boundary reminders

Preserve strict comparison and wraparound.