Given an array of size N and a Linked List where elements will be from the array but can also be duplicated, sort the linked list in the order, elements are appearing in the array. It may be assumed that the array covers all elements of the linked list.
Sorted list =
Asked in Amazon
First, make a hash table that stores the frequencies of elements in linked list. Then, simply traverse list and for each element of arr[i] check the frequency in the has table and modify the data of list by arr[i] element upto its frequency and at last Print the list.
Sort list: 5 -> 5 -> 1 -> 3 -> 2 -> 2 -> 8
- Replace even nodes of a doubly linked list with the elements of array
- Sort even and odd placed elements in increasing order
- Sort even-placed elements in increasing and odd-placed in decreasing order
- Sort a linked list of 0s, 1s and 2s
- Sort an array where a subarray of a sorted array is in reverse order
- Partitioning a linked list around a given value and keeping the original order
- Print Doubly Linked list in Reverse Order
- Partitioning a linked list around a given value and If we don't care about making the elements of the list "stable"
- Sort Linked List containing values from 1 to N
- Merge Sort for Doubly Linked List
- Sort a Linked List in wave form
- Insertion Sort for Doubly Linked List
- C Program for Bubble Sort on Linked List
- Sort the biotonic doubly linked list | Set-2
- Insertion Sort for Singly Linked List
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.