Last Substring in Lexicographical Order
Hard · Two Pointers, String
Given a string s, return the last substring of s in lexicographical order.
Example 1
Input: s = "abab" Output: "bab"
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.
Starter code (python)
class Solution(object):
def lastSubstring(self, s):
"""
:type s: str
:rtype: str
"""
Related problems
- Longest Substring Without Repeating Characters (Medium)
- Longest Palindromic Substring (Medium)
- Container With Most Water (Medium)
Previous: Last Stone Weight II · Next: Height Checker · All problems
Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.