Lexicographically Last Substring
Updated
Problem statement
Consider every different nonempty substring of consecutive characters 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.
More Roblox Online Assessment questions
- Centered Block Placement QueriesOA · Seen Oct 2026
- Robot Navigation Around LasersOA · Seen Oct 2026
- Factory Batch Profit (Game Adaptation)OA · Seen Sep 2026
- Nested Recipe Blocks (Game Adaptation)OA · Seen Sep 2026
- Vehicle Builds for Required Terrain (Game Adaptation)OA · Seen Sep 2026
- Track Received Byte RangesOA · Seen Sep 2026
- Inventory Discount TrackerOA · Seen Sep 2026
- Break a PalindromeOA · Seen Jun 2026
- Count Pairs Differing in One DigitOA · Seen Oct 2025
- Find Zero Cells in a 2×2 GridOA · Seen Oct 2025
Similar questions at other companies
- Longest Subsequence which is a SubstringSalesforce · OASalesforce interview questions
- Palindromic Array TransformationPayPay · OAPayPay interview questions
- String CompressionAbridge · OAAbridge interview questions
- Rearrange String by Alternating EndsHudson River Trading · OAHudson River Trading interview questions
- Alternate String EndsCapital One · OACapital One interview questions
- Minimum Changes for Palindromic BlocksCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- K Smallest SubstringAkuna Capital · OAAkuna Capital interview questions
- Count Binary SubstringsMicrosoft · OAMicrosoft interview questions
- Check a Repeated String as a SubsequenceQuince · OAQuince interview questions
- Format TextTikTok · OATikTok interview questions