Last Substring in Lexicographical Order

Given a string s, return the last substring of s in lexicographical order.

Example 1
Inputs = "abab"
Output"bab"
The substrings are ["a", "ab", "aba", "abab", "b", "ba", "bab"], and the lexicographically maximum substring is "bab".
Example 2
Inputs = "leetcode"
Output"tcode"
The lexicographically maximum substring of s is "tcode".

Constraints

  • 1 <= s.length <= 4 * 10^5
  • s contains only lowercase English letters.

Asked at 5 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate