The diagram below shows a singly linked-list that represents tasks with different deadlines.
The tasks towards the end of the array have deadlines that are closer in time.
Create a function that takes the head of linked-list and moves the task with the closest deadline to the second position in the list, as shown in the diagram below.
The function should only be mutating the given list but not returning a new one.
const listReorder = (head) => {
// Enter your logic here...
}
Examples:
Input: [A,B,C,D]
Output: [A,D,B,C]
Explanation: The task node with the closest deadline has been moved to the second position in the list.
Input: [A,B]
Output: [A,B]
Explanation: The list remains unchanged due to that the list has only 2 node tasks.