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
- Print Doubly Linked list in Reverse Order
- Partitioning a linked list around a given value and keeping the original order
- Sort Linked List containing values from 1 to N
- Partitioning a linked list around a given value and If we don't care about making the elements of the list "stable"
- Traverse Linked List from middle to left-right order using recursion
- Iterative Merge Sort for Linked List
- Sort the biotonic doubly linked list
- Bubble Sort On Doubly Linked List
- Iterative selection sort for linked list
- Insertion Sort for Doubly 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 firstname.lastname@example.org. 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.