Dsa
Stack
Hard
Image Layer Decoder
You are given a string that encodes a series of image layers using a specific syntax. Each layer is represented as 'N[...]', where 'N' is the number of times the layer within the brackets should be repeated. Your task is to decode this string into a flat sequence of layers. Write a program that reads the encoded string and outputs the fully decoded layers.
Input format:
- A single line containing the encoded string (e.g., '3[abc]2[de]').
Output format:
- A single line containing the fully decoded string.
Example:
Input:
3[abc]2[de]
Output:
abcabcabcde
Key concepts
stackdecodingnested structures
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