insidcode
ProblemsDuelLeaderboardStats
Sign In
  1. Home
  2. Problems
  3. Compress a string by replacing repeating characters only if the compressed result is strictly shorter than the original.

Compress a string by replacing repeating characters only if the compressed result is strictly shorter than the original.

Difficulty: Hard

Phase: 6 · Mixed Logical Challenges

XP Reward: 30 XP

Topics: Mixed Logical Challenges, Hard

Supported Languages: Python, JavaScript, C, C++, Java

Problem Description

Compress string by count. Return compressed string only if strictly shorter than original, else return original. Input Format: Read input from standard input (stdin). Output Format: Print the result to standard output (stdout).

Constraints

  • -10^9 <= N <= 10^9

Examples

Example 1

Input: aabcccccaaa

Output: a2b1c5a3

Explanation: Sample execution for input aabcccccaaa