Member-only story
Reorder a Linked List | Coding Interview | Linked List | Medium
5 min readNov 5, 2022
Wow! we are finally close to completing the linked list-based coding problems (just five more to go!). This one is a fairly simple problem with many possible approaches. We will discuss the two major ones, brute force, and efficient ones.
If you are preparing for a coding interview, try out the list I have prepared after comparing many well-known SDE lists.
Now, let’s begin with the topics we will cover.
Table of contents
- Description
- Brute Force Solution
- Efficient Solution
- Conclusion
Description
We are given a linked list that is already sorted, and we have to reorder the list in this way: first->last->second->secondLast, and so on.
A few of the examples are as follows:
Example 1:
Input: 1->2->3->4->5
Output: 1->5->2->4->3Example 2:
Input: 3->6->7
output: 3->7->6