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 October 2026 (Oct 16–31)Sponsored by FLXBL

Contest runs October 16 - 31. Complete challenges to climb the leaderboard!

Prizes 1 & 2: Salesforce certification exam voucher — won by random drawing, where every point is a ticket. see all prizes

Only the 16 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