130. Reverse a Linked List
Core1000 ms256 MBSolved by 0%
Build the list, reverse it by changing the links between nodes, and print the result.
Do not build a second list or an array — reverse the links themselves. That constraint is the whole point.
Print Empty for an empty list.
Constraints - `0 ≤ n ≤ 100000` - `-1000000 ≤ value ≤ 1000000`
Input
The first line contains an integer n, the number of nodes.
The second line contains n space-separated integers — the node values from head to tail.
The starter code builds the list for you; work on the nodes, not the array.
Output
Print the resulting list from head to tail on ONE line, separated by single spaces, or Empty if no nodes remain.
Input5
1 2 3 4 5
Output5 4 3 2 1
Notereverses an ordinary list
Input1
7
Output7
Noteis a single node, where the loop body must not break anything
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution