Split Singly Linked List Alternatingly
Easy Accuracy: 40.18% Submissions: 8310 Points: 2

Given a singly linked list of size N. Your task is to complete the function alternatingSplitList() that splits the given linked list into two smaller list. The sublists should be made from alternating elements from the original list.
Note: the sublist should in the order with respect to original list.

Input Format:
First line of input contains number of testcaes T. First line of each input contains length of the linked list and next line contains the elements of the linked list.

Output Format:
For each test case, in new lines, print the two sublists formed after the split.

User Task:
The task is to complete the function alternatingSplitList() which takes the head as parameter and splits the lists into two. The head of the first list should be stored in the provided variable a, and the head of the second should be stored in the provided variable b. The printing is done by the driver code.

1 <= T <= 100
1 <= N <= 100


0 1 0 1 0 1
2 5 8 9 6

0 0 0
1 1 1
2 8 6
5 9

Testcase 1:
After forming two sublists of the given list as required, we have two lists as: 0->0->0 and 1->1->1.


to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.