Dsa
Recursion
Medium
The Echo Chamber Decompression
You are decoding a compressed transmission. The format is 'k{content}', where 'k' is a positive integer and 'content' is a string or another compressed block. Rules:
1. If 'k' is ODD, simply repeat the decoded 'content' k times.
2. If 'k' is EVEN, repeat the decoded 'content' k times, but REVERSE the content in every even-indexed repetition (1st repeat is normal, 2nd is reversed, 3rd is normal, etc.).
Example: '2{AB}'
- k=2 (even), content='AB'.
- Repeat 1: 'AB', Repeat 2: 'BA'.
- Result: 'ABBA'.
Input: A single string of compressed data.
Output: The fully decompressed string.
Example:
Input: 3{A2{B}}
Output: ABBBABBBABBB (2{B} is even, so 'B' followed by 'B' reversed is 'BB'. Then 3 repeats of 'ABB').
Key concepts
recursionstring manipulationstate management
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now