Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Merge Sort Linked List
MEDIUM
10 mins
18 upvotes
Linked List
Sorting
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Linked List
-
-
Sorting
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Merge Sort Linked List

Contributed by
Prashansa
Medium
yellow-spark
0/80
Avg time to solve 10 mins
Success Rate 90 %
Share
18 upvotes

Problem Statement

You are given a Singly Linked List of integers. Sort the Linked List using merge sort.

Merge Sort is a Divide and Conquer algorithm. It divides the input into two halves, calls itself for the two halves, and then merges the two sorted halves. The merge() function is used for merging two halves. The merge(arr, L, M, R) is a key process that assumes that arr[L..M] and arr[M + 1...R] are sorted and merges the two sorted subarrays into one.

Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
3
1 -2 3 -1
9 9 -1
4 -1
Sample Output 1:
-2 1 3 -1
9 9 -1
4 -1
Explanation For Sample Output 1:
For every test case, the sorted list is printed, terminated by -1.
Sample Input 2:
2
1 1 1 -1
3 -3 -1
Sample Output 2:
1 1 1 -1
-3 3 -1
Reset Code
Full screen
Auto
copy-code
Console