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!
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
Note
You can test your code by connecting to Salesforce, but to save your progress and earn points, you'll need to create an account. Your solutions and achievements will be tracked automatically once you're logged in.