# TCS NQT EYE TEST CODING PROBLEM 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

An organisation is conducting an eye check-up camp, the number of people allowed for registration is 10. A person is supposed to enter his age for registration. If a senior s=citizen above 60 years of age registers then he is shifted to another queue which will be the 2nd queue, now 2 separate queues are created for a check-up. The 2nd queue will be for senior citizens. If the number of people in the 2nd queue becomes 5 then shifting senior citizens from the 1st queue to the 2nd is stopped. Suppose an eye check-up takes approx. 15 min per person, then calculate the total time taken for a check-up by first and queue resp. The number of people who will be registered ‘N’ will be input:

1 <= N <= 10 and Age of a person ‘A’ 10 <= A <= 100

Note:

1. Output should be in the format:

QUEUE1 TIME: <integer> mins

QUEUE2 TIME: <integer> mins

If the age is below 10 or above 100, display “INVALID INPUT”

**Algorithm**

“`

1. Read N.

2. Declare q1 and q2 and set both variables to 0.

3. for i from 0 to n – 1 inclusive, do,

Read age.

if age > 100 or age < 10, do

Print INVALID INPUT

exit

if age > 60 and q2 < 5, do

q2 = q2 + 1

else, do,

q1 = q1 + 1

4. Print QUEUE1 TIME: (q1 * 15)

5. Print QUEUE2 TIME: (q2 * 15)

“`

Program in C

``````#include <stdio.h>
int main()
{
int n, q1 = 0, q2 = 0, age;
scanf("%d", &n);
while (n--)
{
scanf("%d", &age);
if (age > 100 || age < 10)
{
printf("INVALID INPUT");
return 0;
}
if (age > 60 && q2 < 5)
q2 += 1;
else
q1 += 1;
}
printf("QUEUE1 TIME: %d\n", q1 * 15);
printf("QUEUE2 TIME: %d", q2 * 15);
}
``````

Program in C++

``````#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int main() {
int n, q1 {0}, q2 {0}, age;
cin >> n;
while (n--) {
cin >> age;
if ( age > 100 || age < 10 ) {
cout << "INVALID INPUT";
return 0;
}
if ( age > 60 && q2 < 5 )
q2 += 1;
else
q1 += 1;
}
cout << "QUEUE1 TIME: " << q1 * 15 << endl;
cout << "QUEUE2 TIME: " << q2 * 15;
return 0;
}
``````

Program in Java

``````import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int age, q1 = 0, q2 = 0;
while(n > 0)
{
age = in.nextInt();
if (age > 100 || age < 10)
{
System.out.print("INVALID INPUT");
System.exit(0);
}
if (age > 60 && q2 < 5)
q2 += 1;
else
q1 += 1;
n--;
}
System.out.println("QUEUE1 TIME: "+ q1 * 15);
System.out.print("QUEUE2 TIME: "+ q2 * 15);
}
}
``````

Program in Python

``````if __name__ == "__main__":
n = int(input())
q1 = 0
q2 = 0
for _ in range(n):
age = int(input())
if age > 100 or age < 10:
print("INVALID INPUT")
exit(0)
if age > 60 and q2 < 5:
q2 += 1
else:
q1 += 1
print("QUEUE1 TIME:", q1 * 15)
print("QUEUE2 TIME:", q2 * 15)
``````

FOR MORE TCS NQT CODING QUESTIONS 👉👉👉👉 CLICK HERE

### 1 thought on “TCS NQT EYE TEST CODING PROBLEM SOLUTION”

error: Content is protected !!