Zepruv › Coding problems

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

Starter code (python)

class Solution(object):
    def lastSubstring(self, s):
        """
        :type s: str
        :rtype: str
        """
        

Related problems

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.