# TCS NQT Parking Lot Coding Question With Solution

TCS NQT Parking Lot Coding Question With Solution

We at gradjobopenings.com provide free job alerts of freshers job drives. In this website we list on campus job openings for freshers and off campus job openings for freshers and also work from home job openings. This is the best website to apply for off campus drive in India. Visit our website for government job alerts and private job alerts. We also list free interview notes and study materials, one of the best interview study website.comfortable to face the interviews:

Problem Statement

A parking lot in a mall has an 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 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.

Input format:

– First line: A non negative integer R, denoting the number of rows.

– Second line: A non negative integer C, denoting the number of columns.

– Next R lines: C space separated binary values represented by 0 or 1.

Output format :

– First line: An non-negative integer M representing the row containing most number of occupied parking spaces.

Constraints:

1 <= R <= 1000

1 <= C <= 1000

“`

Examples

– Input:

3

3

0 1 0

1 1 0

1 1 1

– Output: 3

– Input:

4

3

0 1 0

1 1 0

1 0 1

1 1 1

– Output: 4

Program In C

``````#include <stdio.h>

int main() {
unsigned int row, col, max_1 = 0, max_row = 1, num, current_count = 0;
scanf("%d%d", &row, &col);
for (unsigned int i = 0 ; i < row ; i++) {
current_count = 0;
for (unsigned int j = 0 ; j < col ; j++) {
scanf("%d", &num);
if (num == 1)
current_count++;
}
if (current_count > max_1) {
max_1 = current_count;
max_row = i + 1;
}
}
printf("%d", max_row);
return 0;
}
``````

Program In C++

``````#include <iostream>

int main() {
unsigned int row, col, max_1 = 0, max_row = 1, num, current_count = 0;
std::cin >> row >> col;
for (unsigned int i = 0 ; i < row ; i++) {
current_count = 0;
for (unsigned int j = 0 ; j < col ; j++) {
std::cin >> num;
if (num == 1)
current_count++;
}
if (current_count > max_1) {
max_1 = current_count;
max_row = i + 1;
}
}
std::cout << max_row;
return 0;
}
``````

Program In Java

``````import java.util.Scanner;

class Main {
public static void main (String args[]) {
int max_1 = 0, max_row = 1, num, current_count = 0;
Scanner in = new Scanner(System.in);
int row = in.nextInt();
int col = in.nextInt();
for (int i = 0 ; i < row ; i++) {
current_count = 0;
for (int j = 0 ; j < col ; j++) {
num = in.nextInt();
if (num == 1)
current_count++;
}
if (current_count > max_1) {
max_1 = current_count;
max_row = i + 1;
}
}
in.close();
System.out.print(max_row);
}
}
``````

Program In Python

``````if __name__ == '__main__':
row = list(map(int, input().split()))
col = row[1]
row = row[0]
max_1 = 0
max_row = 1
for i in range(row):
current_count = input().count('1')
if current_count > max_1:
max_row = i + 1
max_1 = current_count
print(max_row, end = '')
``````

### 1 thought on “TCS NQT Parking Lot Coding Question With Solution”

error: Content is protected !!