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 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.