bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1163. Last Substring in Lexicographical Order

1163. Last Substring in Lexicographical Order

Leetcode Solutions

Two Pointers Approach

  1. Initialize i to 0, j to 1, and k to 0.
  2. While j + k is less than the length of the string s, do the following:
    • If s[i + k] == s[j + k], increment k.
    • If s[i + k] < s[j + k], update i to max(i + k + 1, j), set j to i + 1, and reset k to 0.
    • If s[i + k] > s[j + k], update j to j + k + 1 and reset k to 0.
  3. Return the substring starting from i to the end of the string s.
UML Thumbnail

Brute Force Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...