Merge Two Sorted Lists
Take two already-sorted lists of integers and merge them into one sorted list. Handle null inputs by treating them as empty lists. Both input lists are sorted in ascending order, and the output should also be sorted in ascending order.
Examples:
Input: list1 = [1, 3, 5], list2 = [2, 4, 6]
Output: [1, 2, 3, 4, 5, 6]
Explanation: Merge two sorted lists into one sorted list
Input: list1 = [1, 2, 3], list2 = []
Output: [1, 2, 3]
Explanation: When one list is empty, return the other list
Input: list1 = null, list2 = [1, 2]
Output: [1, 2]
Explanation: Null inputs are treated as empty lists
Input: list1 = null, list2 = null
Output: []
Explanation: Both null inputs result in an empty list
Input: list1 = [1, 1, 2], list2 = [1, 3, 3]
Output: [1, 1, 1, 2, 3, 3]
Explanation: Duplicates are preserved in the merged list
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.