TCS Coding Question 2022 Day 1 Slot 2

Coding Question 1 for 2022 (September slot)

In this article, we will discuss about the TCS Coding Question which is asked in the TCS placement test. This type of Coding Questions will help you to crack your upcoming TCS exam as well as during your inteview process.

TCS Coding Question 1 Day 1 slot 2

TCS Coding Question Day 1 Slot 2 – Question 1

A parking lot in a mall has RxC number of parking spaces. Each parking space will either be  empty(0) or full(1). The status (0/1) of a parking space is represented as the element of the matrix. The task is to find index of the prpeinzta row(R) in the parking lot that has the most of the parking spaces full(1).

Note :

RxC- Size of the matrix

Elements of the matrix M should be only 0 or 1.

Example 1:

Input :

3   -> Value of R(row)

3    -> value of C(column)

[0 1 0 1 1 0 1 1 1] -> Elements of the array M[R][C] where each element is separated by new line.

Output :

3  -> Row 3 has maximum number of 1’s

Example 2:

input :

4 -> Value of R(row)

3 -> Value of C(column)

[0 1 0 1 1 0 1 0 1 1 1 1] -> Elements of the array M[R][C]

Output :

4  -> Row 4 has maximum number of 1’s

7 comments on “TCS Coding Question 2022 Day 1 Slot 2”


  • kimaya

    Python solution

    row = 4
    col = 3
    combined_list = []
    arr =[0,1,0,1,1,0,1,0,1,1,1,1]#[0,1,0,1,1,0,1,1,1] #[0,1,0,1,1,0,1,0,1,1,1,1]

    count = 0
    temp_list = []
    for element in range(0,(row*col)):
    # print(element)
    count += 1
    if count == col+1:
    count = 1

    temp_list.append(arr[element])
    # print(count,element,temp_list)

    if count == col:
    combined_list.append(temp_list)
    temp_list = []

    data_dict_parking_count = dict()

    for count,data in enumerate(combined_list):
    # print(count,data)
    parking_car_count = 0
    for car in data:
    if car == 1:
    parking_car_count +=1
    # print(parking_car_count)
    data_dict_parking_count[“row_”+str(count+1)] = parking_car_count

    max_val = 0
    max_val_key = None
    for key,val in data_dict_parking_count.items():
    print(key,val)
    if max_val < val:
    max_val = val
    max_val_key = str(key)
    print(max_val)
    print(max_val_key)


  • poojitha

    lst=[]
    count=1
    n=int(input())
    for i in range(0,n):
    ele=int(input())
    lst.append(ele)
    print(lst)
    for i in range(1,n):
    if (lst[i]>lst[i-1]-1):
    count+=1
    print(count)


  • Rohit

    C++ program
    #include
    using namespace std;
    int main()
    {
    int row,col;
    //Input of row and column
    cout<>row;
    cout<>col;
    int arr[row][col]; //@-D array of row*col
    int max=INT_MIN;
    int index=0;
    for(int i=0; i<row; i++){
    for(int j=0; j>arr[i][j];
    }
    int count=0;
    for(int j=0; jmax)
    index=i+1;
    }
    cout<<"Most parking spaces are full in row " <<index;
    }


  • Ritika

    class Solution
    {
    public static void main(String[] args)
    { int R,C;
    Scanner sc=new Scanner(System.in);
    R=sc.nextInt();
    C=sc.nextInt();
    int arr[][]=new int[R][C];

    for(int i=0;i<R;i++){
    for(int j=0;j<C;j++){
    arr[i][j]=sc.nextInt();
    }}
    int cmax=0,index=0;
    for(int i=0;i<R;i++)
    { int c=0;
    for(int j=0;jcmax)
    {
    cmax=c;
    index=i+1;
    }
    }
    }
    System.out.println(index);

    }}


    • 21mmc027

      try this!!!
      row=int(input())
      col=int(input())
      s=s1=0
      for i in range(row):
      for j in range(col):
      s+=int(input())
      if s>s1:
      s1=i
      print(s1+1)


  • sayyad

    O(n) solution.
    int func(vector a,int row,int col,int n)
    {
    int ans=0,count=0,maxcount=INT_MIN;
    for (int i = 0; i <n; i++)
    {
    if(a[i]==1) count++;
    if((i+1)%col==0)
    {
    if(maxcount<=count) {ans++;maxcount=max(maxcount,count);}
    count=0;
    }
    }
    return ans;
    }