Handle Score
@Ibrahim Nash 6560
@blackshadows 6400
@mb1973 5777
@Quandray 5271
@akhayrutdinov 5111
@saiujwal13083 5074
@kirtidee18 4356
@sanjay05 3762
@mantu_singh 3638
@gfgaccount 3601
@marius_valentin_dragoi 3525
Complete Leaderboard
Split Singly Linked List Alternatingly
Easy Accuracy: 49.46% Submissions: 9971 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.

Split Singly Linked List Alternatingly

Output Window