We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
It seems that the Problem Statement has changed over time, this solution passes all the test cases, but it only inserts the given data at the correction position in the given Doubly Linked List, it won't generate a sorted list as a outpout. The doubly linked list will only be sorted if the nodes given as input are already in a sorted order.
For example if the following input is given-
1 // Number of Test Cases
4 // Number of elements in the Linked List
2
1
4
3
8 // The the data which need to be inserted in the doubly linked list
The the final output will be -
2 1 4 3 8
as you can see the new data is inserted in the correct order but the doubly linked list itself will remain unsorted. But since all the test cases give the nodes in a sorted order this issue doesn't seem to matter
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Inserting a Node Into a Sorted Doubly Linked List
You are viewing a single comment's thread. Return to all comments →
It seems that the Problem Statement has changed over time, this solution passes all the test cases, but it only inserts the given data at the correction position in the given Doubly Linked List, it won't generate a sorted list as a outpout. The doubly linked list will only be sorted if the nodes given as input are already in a sorted order. For example if the following input is given-
1 // Number of Test Cases
4 // Number of elements in the Linked List
2
1
4
3
8 // The the data which need to be inserted in the doubly linked list
The the final output will be -
2 1 4 3 8
as you can see the new data is inserted in the correct order but the doubly linked list itself will remain unsorted. But since all the test cases give the nodes in a sorted order this issue doesn't seem to matter