Fundamentals/Reverse Doubly Linked List
← PrevNext →
Given a doubly linked list (provided as an array of values), reverse it in place by swapping each node's next and prev pointers, then return the values of the reversed list as an array.
Input
arr: array of values representing the doubly linked list from head to tail
Output
An array of values representing the reversed list from new head to new tail.
Examples
Example 1
Inputarr = [1, 2, 3]
Output[3, 2, 1]
Example 2
Inputarr = []
Output[]
Constraints
0 <= arr.length <= 10^5.
Reverse the list in place (do not allocate new nodes).