Given a run-length encoded string in the format "char+count" pairs, decode it to the original string by repeating each character the specified number of times. The encoded string contains alternating characters and their counts (e.g., "a3b2c1" means 3 a's, 2 b's, and 1 c).
Return null for null input and empty string for empty input.
Examples:
Input: encoded = "a3b2c1"
Output: "aaabbc"
Explanation: Decode to 3 a's, 2 b's, and 1 c
Input: encoded = "x5"
Output: "xxxxx"
Explanation: Decode to 5 x's
Input: encoded = "a1b1c1"
Output: "abc"
Explanation: Each character appears once
Input: encoded = null
Output: null
Explanation: Return null for null input
Input: encoded = ""
Output: ""
Explanation: Return empty string for empty input
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay July 2026
Contest runs July 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.