Problem · String
Alphabetically Maximum Substring
Learn this problemProblem statement
Given a string s containing lowercase English letters, return its lexicographically greatest non-empty substring.
A substring is a contiguous sequence of characters from s. String a is lexicographically greater than string b when either:
- At the first position where they differ,
ahas the greater character. bis a proper prefix ofa.
Function
alphabeticallyMaximumSubstring(s: String) → StringExamples
Example 1
s = "abab"return = "bab"The substring bab begins with b, so it is greater than every substring beginning with a. It is also greater than the one-character substring b because b is its proper prefix.
Example 2
s = "leetcode"return = "tcode"The only occurrence of the greatest character t begins the substring tcode, which is therefore greater than every other substring.
Example 3
s = "aaaa"return = "aaaa"Every candidate contains only a. The full string is greatest because every shorter candidate is its proper prefix.
Constraints
1 <= s.length <= 200000scontains only lowercase English letters.
More Oracle problems
- Best Time to Buy and Sell StockPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Enumerate Right-and-Down Matrix PathsONSITE INTERVIEW · Seen Jul 2026
- Maximize Movie Ratings Without Consecutive SkipsONSITE INTERVIEW · Seen Jul 2026
- Add One to a Number Represented as DigitsONSITE INTERVIEW · Seen Jul 2026
- Top K Frequent Elements with Larger-Value Tie BreakONSITE INTERVIEW · Seen Jul 2026
- Merge k Sorted ListsPHONE SCREEN · Seen Jul 2026
- Implement a Queue Using Two StacksPHONE SCREEN · Seen Jul 2026
- First Balanced Removal IndexOA · Seen Dec 2025