You are provided with a singly linked list, all you have to do is to delete the last node of the linked list and add it to the front of the linked list.
Example:

Please note that the linked list will only contain numeric values.
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case will contain the elements of the linked list separated by a single space and terminated by -1. Hence, -1 would never be a list element.
Output Format:
For each test case, return the new head node of the linked list after adding the last node to its front.
Print the output of each test case in a separate line.
Note:
You don’t need to print anything, It has already been taken care of. Just implement the given function.
1 <= T <= 10
0 <= N <= 10000
-10^4 <= LIST[i] <= 10^4
Where 'N' is the total number of nodes in the given linked list. ‘LIST[i]’ represents the node value of the node ‘i’.
Time limit: 1 sec
2
2 5 3 11 1 -1
2 -1
1 2 5 3 11 -1
2 -1
In test case 1, the new linked list after doing delete and add operations to the last node: 1 2 5 3 11 -1.
In test case 2, the linked list has only one node and so, the last node is itself at the front.
2
4 3 -1
1 1 1 1 -1
3 4 -1
1 1 1 1 -1
In test case 1, the new linked list after doing delete and add operations to the last node: 3 4 -1.
In test case 2, the new linked list after swapping first and last nodes: 1 1 1 1 -1.
Can you break the linked list into two parts?
The basic idea is to break the linked list into two parts at the second last node position and then swap both halves.
The Steps are as follows:
O(N), Where ‘N’ is the length of the given linked list.
Since we are iterating through the list once, so the overall time complexity will be O(N).
O(1)
Since we are not using any extra space, so the overall space complexity will be O(1).