TCS NQT Restaurant Coding Question With Solution
‘N’ number of customers are waiting at a restaurant that is recently opened. After every ‘M’ minutes, a new customer arrives at the restaurant. Due to the huge crowd, customers have to wait for their table at the restaurant. Only one customer is allowed at a time. The manager at the reception desk asks each customer to wait for ‘X’ minutes to get their table. The task is to calculate the duration (in minutes) the last customer arrived needs to wait.
**Input format**:
– First line: 3 Space-separated non-negative integers N, M, X as described in the problem statement.
**Output format**:
– First line: A non-negative integer as described in the problem statement.
**Example 1:**
– Input: 5 3 10 -> Value of N, Value of M, Value of X
– Output: 28
– Explanation:
Customers | Customer 1 | Customer 2 | Customer 3 | Customer 4 | Customer 5 |
Arrival time | 0 | 3 | 6 | 9 | 12 |
Duration ( mins ) Customer can enter | 10 | 20 | 30 | 40 | |
Waiting Time | 0 | 7 | 14 | 21 | 28 |
– The last customer arrives at the restaurant at the 12th minute, and he gets a table at 40 minutes. So, the total duration the last customer waited to get a table is 40-12=28 minutes. Hence, the output is 28.
Example 2:
– Input: 3 5 5 -> Value of N, Value of M, Value of X
– Output: 0
– Explanation:
Customers | Customer 1 | Customer 2 | Customer 3 |
Arrival Time | 0 | 5 | 10 |
Duration (mins) Customer Can Enter | 5 | 10 | |
Waiting Time | 0 | 0 | 0 |
– The last customer arrives at the restaurant at the 10th minute, and he gets a table after 10 minutes. So, the total duration the last customer waited to get a table is 10-10=0. I.e. no need to wait. Hence, the output is 0.
**Constraints:**
– 0 < N <= 50
– 0 < M <= 60
– 0 < X <= 60
**Program in C**
#include <stdio.h>
int main() {
unsigned short int n, m, x;
scanf("%hu%hu%hu", &n, &m, &x);
int last_customer = m * (n - 1);
int last_customer_wait_duration = x * (n - 1);
printf("%d", last_customer_wait_duration - last_customer);
return 0;
}
**Program in C++**
#include <iostream>
int main() {
unsigned short int n, m, x;
std::cin >> n >> m >> x;
int last_customer = m * (n - 1);
int last_customer_wait_duration = x * (n - 1);
std::cout << last_customer_wait_duration - last_customer;
return 0;
}
**Program in Java**
import java.util.*;
class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
int x = in.nextInt();
in.close();
int last_customer = m * ( n - 1 );
int last_customer_wait_duration = x * ( n - 1 );
System.out.print(last_customer_wait_duration - last_customer);
}
}
**Program in Python**
if __name__ == '__main__':
n, m, x = tuple (map (int, input().split()))
print( x * (n - 1) - m * (n - 1), end = '')
Pingback: TCS NQT CODING QUESTIONS WITH SOLUTIONS - GRAD JOB OPENINGS