![]() |
VOOZH | about |
Given a linked list, print alternate nodes of this linked list.
Examples :
Input : 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 10 Output : 1 -> 3 -> 5 -> 7 -> 9 Input : 10 -> 9 Output : 10
Recursive Approach :
Implementation:
1 3 5 7 9
Time complexity: O(N) where N is no of nodes in linked list
Auxiliary space: O(1), If we consider recursive call stack then it would be O(n)