Grokking Coding Mock Interview
Ask Author
Back to course home

0% completed

Vote For New Content

String Compression III (medium)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given a string named word, compress this string using the following rule:

  • Start with an empty string named comp.
  • While there are still characters left in word, perform the following:
    • Take the longest possible prefix made of a single repeated character, but limit the length to 9 characters maximum.
    • Remove this prefix from word.
    • Add the number of characters followed by the character itself to comp.

Return the final compressed string comp.

Examples

Example 1:

  • Input: word = "bbbbbbbeee"

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible