Given two strings, interleave them by alternating characters from each string. Start with the first character of the first string, then the first character of the second string, then the second character of the first string, and so on. If one string is longer than the other, append the remaining characters to the end. Treat null inputs as empty strings.

Examples:

Input: s1 = 'abc', s2 = 'xyz' Output: 'axbycz' Explanation: Characters alternate: a, x, b, y, c, z Input: s1 = 'abcd', s2 = 'xy' Output: 'axbycd' Explanation: After interleaving, remaining characters from s1 are appended Input: s1 = '', s2 = 'hello' Output: 'hello' Explanation: Empty first string means only second string characters remain Input: s1 = null, s2 = null Output: ''
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 4–15)Sponsored by FLXBL

Contest runs October 4 - 15. 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 12 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