Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5761 |

@blackshadows | 5715 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 1115 |

@bt8816103042 | 739 |

@thealchemist627 | 456 |

@dalwainazism125 | 453 |

@akashkale117 | 453 |

@shivanandp12345678910 | 453 |

@codeantik | 448 |

@SherlockHolmes3 | 447 |

@SHOAIBVIJAPURE | 430 |

@shalinibhataniya1097 | 408 |

@ShamaKhan1 | 392 |

Complete Leaderboard |

Given a linked list, the task is to move all 0’s to the front of the linked list. The order of all another element except 0 should be same after rearrangement.

**Input:**

The first line of input contains an integer **T **denoting the number of test cases. For each test case, the first line contains an integer **N **denoting the number of elements in the Linked List and the second line contains N-space separated integer inputs i.e. elements in the Linked List.

**Output:**

For each test case, the output is the modified linked list having all 0's in front.

**User Task:**

The task is to complete the function **moveZeroes**() which should move all the 0's to the front of the list.

**Constraints:**

1 <= T <= 100

1 <= N <= 50

**Note: **List is from back to front.

**Example:
Input:**

2

10

0 1 0 1 2 0 5 0 4 0

7

0 0 0 3 2 1 1

**Output:**

0 0 0 0 0 4 5 2 1 1

0 0 0 1 1 2 3

**Explanation:
1. **Original list was 0->4->0->5->0->2->1->0->1->0->NULL.

After processing list becomes 0->0->0->0->0->4->5->2->1->1->NULL.

After processing list becomes 0->0->0->1->1->2->3->NULL.

Login 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?

Yes
Move all zeros to the front of the linked list

...