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!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow 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 Mar/April 2026
Contest runs March 3 - April 30. Complete challenges to climb the leaderboard!
Points are calculated for challenges completed during the contest period.