![]() |
VOOZH | about |
Given a linked list, split the linked list into two with alternate nodes.
Examples:
Input : 1 2 3 4 5 6 7 Output : 1 3 5 7 2 4 6 Input : 1 4 5 6 Output : 1 5 4 6
We have discussed Iterative splitting of linked list.
The idea is to begin from two nodes first and second. Let us call these nodes as 'a' and 'b'. We recurs
Implementation:
a : 1 3 5 7 b : 2 4 6
Time Complexity: O(N)
Auxiliary Space: O(N)