Problem · String

String Compression Problem

Learn this problem
EasySalesforce logoSalesforceFULLTIMEOA
See Salesforce hiring insights

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

Examples

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

drafts saved locally
public String compressString(String input) {
  // write your code here
}
input"abaasass"
expected"a1b1a2s1a1s2"
checking account