Lexicographically Last Substring
Problem statement
Consider every distinct nonempty contiguous substring of s, sorted in ascending lexicographic order. Return the last string in that order.
For this exercise, assume s contains lowercase English letters. Compare strings at their first differing letter; if one is a prefix of the other, the longer string is larger. Return an empty string when s is empty.
You only need to return the selected substring, not construct or return the full collection of substrings.
Function
lastSubstring(s: String) → StringExamples
Example 1
s = "abab"return = "bab"Among the substrings starting with b, bab is larger than b. Every substring starting with a is smaller.
Example 2
s = "leetcode"return = "tcode"t is the largest available first letter, and its full suffix is the largest substring starting there.
Example 3
s = "aaaa"return = "aaaa"When strings share a prefix, the longer one is larger.
Constraints
0 <= s.length <= 5000.- Every character is a lowercase English letter.