Problem · String
String Compression Problem
Learn this problemProblem statement
Given a string input, replace each maximal consecutive run of the same character with that character followed by the run length.
Return the complete run-length encoded string, even when it is longer than input.
Function
compressString(input: String) → StringExamples
Example 1
input = "abaasass"return = "a1b1a2s1a1s2"
The consecutive runs are a, b, aa, s, a, and ss. Writing each run as its character followed by its length produces a1b1a2s1a1s2.
More Salesforce problems
- Diameter of an Acyclic Undirected GraphONSITE INTERVIEW · Seen Jul 2026
- Optimal Account BalancingPHONE SCREEN · Seen Jul 2026
- Longest Increasing SubsequencePHONE SCREEN · Seen Jul 2026
- Maximal SquarePHONE SCREEN · Seen Jul 2026
- Maximum Barbell WeightOA · Seen Jul 2026
- Minimum No-Repeat Segments After One Character RemovalOA · Seen Jul 2026
- Minimum Operations to ZeroOA · Seen Jul 2026
- Minimize Total Input Cost (for LTMS)OA · Seen Jun 2026