Error
Handle  Score 

@Ibrahim Nash  6420 
@blackshadows  6380 
@mb1973  5642 
@Quandray  5233 
@akhayrutdinov  5111 
@saiujwal13083  4510 
@sanjay05  3762 
@kirtidee18  3673 
@marius_valentin_dragoi  3522 
@sushant_a  3459 
@verma_ji  3413 
Complete Leaderboard  
Handle  Score 
@sanskar94511  539 
@akashverma4  303 
@swastik8750  237 
@nishunishuraj18  223 
@nayan2709  211 
@ajaybhardwaj1999  196 
@surajmamgai  193 
@AnshikaPandey  192 
@gurshehzadsingh  188 
@Rajpra786  185 
@shardul08  185 
Complete Leaderboard 
Given a Linked List of size N, where every node represents a sublinkedlist and contains two pointers:
(i) a next pointer to the next node,
(ii) a bottom pointer to a linked list where this node is head.
Each of the sublinkedlist is in sorted order.
Flatten the Link List such that all the nodes appear in a single level while maintaining the sorted order.
Note: The flattened list will be printed using the bottom pointer instead of next pointer.
Example 1:
Input:
5 > 10 > 19 > 28
   
7 20 22 35
  
8 50 40
 
30 45
Output: 5> 7> 8 > 10 > 19> 20>
22> 28> 30> 35> 40> 45> 50.
Explanation:
The resultant linked lists has every
node in a single level.
(Note:  represents the bottom pointer.)
Example 2:
Input:
5 > 10 > 19 > 28
 
7 22
 
8 50

30
Output: 5>7>8>10>19>20>22>30>50
Explanation:
The resultant linked lists has every
node in a single level.
(Note:  represents the bottom pointer.)
Your Task:
You do not need to read input or print anything. Complete the function flatten() that takes the head of the linked list as input parameter and returns the head of flattened link list.
Expected Time Complexity: O(N*M)
Expected Auxiliary Space: O(1)
Constraints:
0 <= N <= 50
1 <= M_{i} <= 20
1 <= Element of linked list <= 10^{3}
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes