tcs nqt Restaurant Coding Questions Previous Paper

TCS NQT Restaurant Coding Question With Solution

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:

CustomersCustomer 1Customer 2Customer 3Customer 4Customer 5
Arrival time 036912
Duration ( mins )
Customer can enter
10203040
Waiting Time07142128

– 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:

CustomersCustomer 1Customer 2Customer 3
Arrival Time0510
Duration (mins)
Customer Can Enter
510
Waiting Time 000

– 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 = '')

1 thought on “TCS NQT Restaurant Coding Question With Solution”

  1. Pingback: TCS NQT CODING QUESTIONS WITH SOLUTIONS - GRAD JOB OPENINGS

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!