FastPrepFastPrep
Problem Brief

String Compression Problem

FULLTIMEOA

Given a string, write a function to compress it by shortening every sequence of the same character to that character followed by the number of repetitions. If the compressed string is longer than the original, you should return the original string.

Function Description

Complete the function compressString in the editor.

compressString has the following parameter:

  1. String input: the string to compress

Returns

String: the compressed string or the original string if the compressed one is longer

1Example 1

Input
input = "abaasass"
Output
"a1b1a2s1a1s2"
Explanation
:)
public String compressString(String input) {
  // write your code here
}
Input

input

"abaasass"

Output

"a1b1a2s1a1s2"

Sign in to submit your solution.