Prime #### Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime #### Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

# TCS Coding Questions 2022 Day 1 Slot 1

## Coding Question 1 for 2022 (September slot) ### TCS Coding Question Day 1 Slot 1 – Question 1

A chocolate factory is packing chocolates into the packets. The chocolate packets here represent an array arrt of N number of integer values. The task is to find the empty packets(0) of chocolate and push it to the end of the conveyor belt(array).

For Example:

N=7 and arr = [4,5,0,1.9,0,5,0].

There are 3 empty packets in the given set. These 3 empty packets represented as O should be pushed towards the end of the array

Example 1:

Input:

7  – Value of N

[4,5,0,1,0,0,5] – Element of arr[O] to arr[N-1],While input each element is separated by newline

Output:

4 5 1 9 5 0 0

Example 2:

Input:

6

— Value of N.

[6,0,1,8,0,2] – Element of arr to arr[N-1], While input each element is separated by newline

Output:

6 1 8 2 0 0

`#include <bits/stdc++.h>using namespace std;int main(){    int n,j=0; cin>>n;    int a[n]={0};    for(int i=0;i<n;i++)    {        cin>>a[j];        if(a[j]!=0) j++;    }    for(int i=0;i<n;i++) cout<<a[i]<<" ";}`
`import java.util.*;class Solution{    public static void main (String[]args)    {        Scanner sc = new Scanner (System.in);        int n = sc.nextInt ();        int arr[] = new int[n];            for(int i = 0; i < n; i++)            arr[i] = sc.nextInt ();        int count = 0;            for(int i = 0; i < n; i++)            if (arr[i] != 0)	            arr[count++] = arr[i];        for(int i = count; i < n; i++)            arr[i] = 0;        for (int i = 0; i < n; i++)            System.out.print (arr[i] + " ");    }}`
`n=int(input())j=0L=[0 for i in range(n)]for i in range(n):    a=int(input())    if a!=0:        L[j]=a        j+=1for i in L:    print(i,end=" ")`