FastPrepRun-Length String Compression
Problems/Run-Length String Compression

Run-Length String Compression

Roblox logoRoblox● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The candidate names a string-compression task without its encoding rules. This version uses run-length encoding of consecutive characters, with the counts written out, lowercase input, a rule for empty input, and limits. Our version is about 70% the same as the reported question.

Compress a string s using run-length encoding.

For this exercise, assume s contains only lowercase English letters. Split the string into groups of consecutive equal letters, starting a new group only when the letter changes. Replace each whole group with its letter followed by the group’s length in decimal digits. Include 1 for a single letter. Join the encoded groups in their original order.

Return the encoded string even when it is longer than the input. An empty input returns an empty string. Runs separated by another letter remain separate; this is consecutive-run compression, not a total frequency count.

Function

compressRuns(s: String) → String

Examples

Example 1

s = "aaabbc"return = "a3b2c1"

The consecutive runs are aaa, bb and c, with lengths 3, 2 and 1.

Example 2

s = "aba"return = "a1b1a1"

The two a runs are separated, so they cannot be combined.

Example 3

s = ""return = ""

An empty string contains no runs.

Constraints

  • 0 <= s.length <= 1000.
  • 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

  • Rearrange String by Alternating EndsHudson River Trading · OAHudson River Trading interview questions
  • Alternate String EndsCapital One · OACapital One interview questions
  • Run-Length String CompressionSalesforce · OASalesforce interview questions
  • Minimum Changes for Palindromic BlocksCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
  • Count Binary SubstringsMicrosoft · OAMicrosoft interview questions
  • Check a Repeated String as a SubsequenceQuince · OAQuince interview questions
  • Reverse String In PlaceThe Walt Disney Company · OA · PHONE SCREENThe Walt Disney Company interview questions
  • Lost MessagesSuperhuman · OASuperhuman interview questions
  • Reverse a StringFlexTrade · OAFlexTrade interview questions
  • Missing WordsVanguard · OAVanguard interview questions
All Roblox interview questionsSee Roblox hiring insights
Saved
class Solution {
    public String compressRuns(String s) {
        // write your code here
    }

}
Checking account…