TCS NQT Menu9>
- Placement Papers
- What is TCS NQT?
- How To Apply
- Foundation Section
- Aptitude Questions
- English Verbal
- Reasoning Ability
- Advanced Section
- Advanced Quantitative Ability
- Advanced Reasoning Ability
- Advanced Coding
- Coding Questions
- Syllabus 2024
- Recruitment Process
- Registration Process
- Eligibility Criteria
- How to prepare for TCS NQT?
- Interview Questions
- Hiring Process
PREPINSTA PRIME
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 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)
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)
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)
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;
}
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);
}}
if i run this python code the code is running but output is not coming
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)
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;
}