• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
October 29, 2024 |180 Views

SDE Sheet - Flattening a Linked List

  Share   Like
Description
Discussion

This video is part of the Linked List section under GFG SDE Sheet.

Given a Linked List, where every node represents a sub-linked-list 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 sub-linked lists is in sorted order.
Flatten the Link List so 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 the next pointer. Look at the printList() function in the driver code for more clarity.

Examples:

Input:
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.)

Do check out:-
Problem: https://www.geeksforgeeks.org/problems/flattening-a-linked-list/1
SDE Sheet Link: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/
Article Link: https://www.geeksforgeeks.org/flattening-a-Linked-list/