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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Sort all even numbers in ascending order and then sort all odd numbers in descending order
- Sort elements of an array in increasing order of absolute difference of adjacent elements
- Sort first k values in ascending order and remaining n-k values in descending order
- Longest subsequence with at least one character appearing in every string
- Number of steps to sort the array by changing order of three elements in each step
- Comparison among Bubble Sort, Selection Sort and Insertion Sort
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Merge a linked list into another linked list at alternate positions
- Check if a linked list is Circular Linked List
- Convert singly linked list into circular linked list
- Difference between Singly linked list and Doubly linked list
- Convert Singly Linked List to XOR Linked List
- Create new linked list from two given linked list with greater element at each node
- Add elements in start to sort the array | Variation of Stalin Sort
- Why Quick Sort preferred for Arrays and Merge Sort for Linked Lists?
- Sort an array according to the order defined by another array
- Sort even-placed elements in increasing and odd-placed in decreasing order
- Sort even and odd placed elements in increasing order
- Partitioning a linked list around a given value and If we don't care about making the elements of the list "stable"
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.