FastPrepLexicographically Last Substring
Problems/Lexicographically Last Substring

Lexicographically Last Substring

Roblox logoRoblox● HardNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The candidate asks for the last string after sorting all the distinct substrings in ascending order. This version uses non-empty unbroken substrings, lowercase letters, a result for empty input, and a limit on length. Our version is about 95% the same as the reported question.

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) → String

Examples

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

Interview reports that mention this question

  • Roblox OA: What It Tests (2026)
  • Roblox New Grad Early OA Tasks: 10 Experiences (Part 7 of 7)

Roblox interview experiences

  • Roblox New Grad Engineer Rounds: 13 Experiences (Part 6 of 7)
  • Roblox New Grad HackerRank OA: 18 Experiences (Part 5 of 7)
  • Roblox New Grad CodeSignal Finals: 23 Experiences (Part 4 of 7)
  • Roblox New Grad Games and BQ: 25 Experiences (Part 3 of 7)
All Roblox interview questionsSee Roblox hiring insights
Saved
class Solution {
    public String lastSubstring(String s) {
        // write your code here
    }

}
Checking account…