Linked List pattern
Merge Two Sorted Lists
Merge two sorted linked lists into one sorted list by splicing their nodes together, and return its head. Watch it run step by step, then write your own pseudocode and get it checked by AI.
- LeetCode 21
- Easy
- 2 approaches
Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.
Linked ListLeetCode 21
Easy
From the first idea to the best one
- 01 Naive · collect + sort O((n+m) log(n+m))O(n+m) space
- 02 Optimized · two pointers O(n + m)O(1) space
What you will learn
- How to read Merge Two Sorted Lists and spot the linked list pattern in it
- Naive · collect + sort: O((n+m) log(n+m)) time, O(n+m) space
- Optimized · two pointers: O(n + m) time, O(1) space
- The pseudocode for each approach, its line lit as the animation runs
- Practice: write your own pseudocode and get it checked
More Linked List
See Merge Two Sorted Lists run, step by step
Sign in and this page opens on the animation, with all 9 Linked List problems beside it.
DSA comes with the all labs plan and every ChaiCode batch.