[Expected Approach] Traverse Till Last Node - O(n) Time and O(1) space:
Traverse the list till the last node. Use two pointers to store the reference of the last node and second last node. After the end of loop, make the second last node as the last node and the last node as the head node.
Below is the implementation of the above approach:
Output
Linked list before:
1 2 3 4 5
Linked list after:
5 1 2 3 4
Time Complexity: O(n), As we need to traverse the list once. Auxiliary Space: O(1)