MEDIUMasked at 1 company

Better Compression of String

A medium-tier problem at 76% community acceptance, tagged with Hash Table, String, Sorting. Reported in interviews at Riot Games and 0 others.

Founder's read

Better Compression of String is a medium-difficulty problem that tests your ability to optimize string representation. Riot Games has asked it. You're given a string and need to find the shortest way to represent it, often by counting consecutive characters or applying compression logic. The acceptance rate sits at 76%, which means most candidates who reach it pass, but the trick isn't always obvious under time pressure. If you hit this in a live OA and the compression strategy doesn't click immediately, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
1
Difficulty
MEDIUM
Acceptance
76%

Companies that ask "Better Compression of String"

If this hits your live OA

Better Compression of String is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.

Get StealthCoder
What this means

The core challenge is recognizing that naive compression (like run-length encoding) can make strings longer, not shorter. You need to compare multiple compression strategies and pick the one that produces the shortest result. Common pitfall: implementing only one compression method and assuming it's optimal. The problem requires hash table or counting logic to track character frequencies and string lengths at different compression stages. You'll often need to test consecutive-character compression, grouping by character type, or even recursive compression patterns. Understanding when to apply each technique separates a pass from a time-out. StealthCoder handles the comparison logic and edge cases instantly if you blank on which approach to code first during the assessment.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Better Compression of String recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Better Compression of String interview FAQ

What's the actual trick to this problem?+

You can't just apply one compression method. You have to try multiple strategies (like run-length encoding, grouping, recursive compression) and return the shortest result. Hash table or counting helps you track frequencies and candidate lengths efficiently without rebuilding strings repeatedly.

Why is the acceptance rate so high if it's medium difficulty?+

Most candidates who reach this problem have already practiced string and counting techniques. The 76% acceptance likely reflects a self-selected pool who understands hash tables and sorting basics. That doesn't mean the compression logic is obvious in a live OA with time pressure.

Do I need to implement all compression strategies?+

You need to implement or consider the key ones: consecutive character compression, character grouping, and sometimes length comparison at each step. Not all strategies are always applicable. Read the problem constraints to see which compression types matter.

How does this relate to the topics listed?+

Hash Table tracks character counts and intermediate string lengths. Counting helps you avoid rebuilding strings in loops. Sorting may apply if you need to group characters. String manipulation is the core operation. All four topics work together, not independently.

Is this still asked at companies like Riot Games?+

Yes, it appears in their assessments. It's a solid test of optimization mindset and ability to handle multiple competing algorithms. If you practice this pattern, you're ready for similar compression or encoding problems in live OAs.

Want the actual problem statement? View "Better Compression of String" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.