• 0

String compression using the counts of repeated characters.


Input : A string // aaaabbc
Output : A string // a4b2c1

Logic :

  • Iterate over the string
  • Compare the current and next characters.
  • If both characters are not same,
    • Then increment the count by 1 and do string concatenation.

Solution :