Given a string s, return the last substring of s in lexicographical order.
Examples
Example 1
Input: s = "abab"
Output: "bab"
Explanation: The substrings are ["a", "ab", "aba", "abab", "b", "ba", "bab"]. The lexicographically maximum substring is "bab".
Example 2
Input: s = "leetcode"
Output: "tcode"
Constraints
1 <= s.length <= 4 * 105
s contains only lowercase English letters.
1163. Last Substring in Lexicographical Order
Hard
50 Points
Two Pointers
String
Given a string s, return the last substring of s in lexicographical order.
Examples
Example 1
Input: s = "abab"
Output: "bab"
Explanation: The substrings are ["a", "ab", "aba", "abab", "b", "ba", "bab"]. The lexicographically maximum substring is "bab".
Example 2
Input: s = "leetcode"
Output: "tcode"
Constraints
1 <= s.length <= 4 * 105
s contains only lowercase English letters.
Last Substring in Lexicographical Order - Practice Coding | SlaveCode