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

#include <bits/stdc++.h>
using namespace std;

int main()
{
int r,c,a,sum=0,m=INT_MIN,in=0;
cin>>r>>c;
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cin>>a;
sum+=a;
}
if(sum>m)
{
m=sum;
in=i+1;
}
sum=0;
}
cout<<in;
}
import java.util.*;
class Solution
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int row=sc.nextInt();
int col=sc.nextInt();
int arr[][]=new int[row][col];

for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
arr[i][j]=sc.nextInt();

int max=0,count=0,index=0;
for(int i=0;i<row;i++)
{ count=0;
for(int j=0;j<col;j++)
{
if(arr[i][j]==1)
count++;
}
if(count>max)
{
max=count;
index=i+1;
}
}
System.out.println(index);
}
}
r=int(input())
c=int(input())
sum=0
m=0
id=0
for i in range(r):
for j in range(c):
sum+=int(input())
if sum>m:
m=sum
id=i+1
sum=0
print(id)