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 September 2026 (Sep 1–15)Sponsored by FLXBL

Contest runs September 1 - 15. Complete challenges to climb the leaderboard!

1st & 2nd: Salesforce certification exam voucher see all prizes

Only the 15 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In