*889*

Table of Contents

**This article will explore recurring question types across different TCS NQT exams.**

## Question 1

**Problem Statement**: A supermarket maintains a pricing format for all its products. A value N is printed on each product. When the scanner reads the value N on the item, the product of all the digits in the value N is the price of the item. The task here is to design the software such that given the code of any item N the product (multiplication) of all the digits of value should be computed(price).

**Example 1:**

**Input :**

5244 -> Value of N

**Output :**160 -> Price

**Explanation:**

From the input above

Product of the digits 5,2,4,4

5*2*4*4= 160

Hence, output is 160.

## Question 2

**Problem Statement**: A furnishing company is manufacturing a new collection of curtains. The curtains are of two colors aqua(a) and black (b). The curtains color is represented as a string(str) consisting of a’s and b’s of length N. Then, they are packed (substring) into L number of curtains in each box. The box with the maximum number of ‘aqua’ (a) color curtains is labeled. The task here is to find the number of ‘aqua’ color curtains in the labeled box.

**Note :**

If ‘L’ is not a multiple of N, the remaining number of curtains should be considered as a substring too. In simple words, after dividing the curtains in sets of ‘L’, any curtains left will be another set(refer example 1)

**Example 1:**

**Input :**

bbbaaababa -> Value of str

3 -> Value of L

**Output:**

3 -> Maximum number of a’s

**Explanation:**

From the input given above.

Dividing the string into sets of 3 characters each

Set 1: {b,b,b}

Set 2: {a,a,a}

Set 3: {b,a,b}

Set 4: {a} -> leftover characters also as taken as another set

Among all the sets, Set 2 has more number of a’s. The number of a’s in set 2 is 3.

Hence, the output is 3.

**Example 2:**

**Input :**

abbbaabbb -> Value of str

5 -> Value of L

**Output**:

2 -> Maximum number of a’s

**Explanation**:

From the input given above,

Dividing the string into sets of 5 characters each.

Set 1: {a,b,b,b,b}

Set 2: {a,a,b,b,b}

Among both the sets, set 2 has more number of a’s. The number of a’s in set 2 is 2.

Hence, the output is 2.

**Constraints:**

1<=L<=10

1<=N<=50

The input format for testing

The candidate has to write the code to accept two inputs separated by a new line.

First input- Accept string that contains character a and b only

Second input- Accept value for N(Positive integer number)

The output format for testing

The output should be a positive integer number of print the message(if any) given in the problem statement.(Check the output in Example 1, Example 2).

## Question 3

**Problem Statement**: An international round table conference will be held in india. Presidents from all over the world representing their respective countries will be attending the conference. The task is to find the possible number of ways(P) to make the N members sit around the circular table such that.

The president and prime minister of India will always sit next to each other.

**Example 1:**

**Input :**

4 -> Value of N(No. of members)

**Output : **

12 -> Possible ways of seating the members

**Explanation:**

2 members should always be next to each other.

So, 2 members can be in 2!ways

Rest of the members can be arranged in (4-1)! ways.(1 is subtracted because the previously selected two members will be considered as single members now).

So total possible ways 4 members can be seated around the circular table 2*6= 12.

Hence, output is 12.

**Example 2:**

**Input:**

10 -> Value of N(No. of members)

**Output :**

725760 -> Possible ways of seating the members

**Explanation:**

2 members should always be next to each other.

So, 2 members can be in 2! ways

Rest of the members can be arranged in (10-1)! Ways. (1 is subtracted because the previously selected two members will be considered as a single member now).

So, total possible ways 10 members can be seated around a round table is

2*362880 = 725760 ways.

Hence, output is 725760.

The input format for testing

The candidate has to write the code to accept one input

First input – Accept value of number of N(Positive integer number)

The output format for testing

The output should be a positive integer number or print the message(if any) given in the problem statement(Check the output in example 1, example2)

**Constraints :**

2<=N<=50

## Question 4

**Problem Statement**: An intelligence agency has received reports about some threats. The reports consist of numbers in a mysterious method. There is a number “N” and another number “R”. Those numbers are studied thoroughly and it is concluded that all digits of the number ‘N’ are summed up and this action is performed ‘R’ number of times. The resultant is also a single digit that is yet to be deciphered. The task here is to find the single-digit sum of the given number ‘N’ by repeating the action ‘R’ number of times.

If the value of ‘R’ is 0, print the output as ‘0’.

**Example 1:**

**Input :**

99 -> Value of N

3 -> Value of R

**Output :**

9 -> Possible ways to fill the cistern.

**Explanation:**

Here, the number N=99

- Sum of the digits N: 9+9 = 18
- Repeat step 2 ‘R’ times i.e. 3 tims (9+9)+(9+9)+(9+9) = 18+18+18 =54
- Add digits of 54 as we need a single digit 5+4

Hence , the output is 9.

**Example 2:**

**Input :**

1234 -> Value of N

2 -> Value of R

**Output :**

2 -> Possible ways to fill the cistern

**Explanation:**

Here, the number N=1234

- Sum of the digits of N: 1+2+3+4 =10
- Repeat step 2 ‘R’ times i.e. 2 times (1+2+3+4)+(1+2+3+4)= 10+10=20
- Add digits of 20 as we need a single digit. 2+0=2

Hence, the output is 2.

**Constraints:**

0<N<=1000

0<=R<=50

The Input format for testing

The candidate has to write the code to accept 2 input(s)

First input- Accept value for N (positive integer number)

Second input: Accept value for R(Positive integer number)

The output format for testing

The output should be a positive integer number or print the message (if any) given in the problem statement. (Check the output in Example 1, Example 2).

## Question 5

**Problem Statement**: Particulate matters are the biggest contributors to Delhi pollution. The main reason behind the increase in the concentration of PMs include vehicle emission by applying Odd Even concept for all types of vehicles. The vehicles with the odd last digit in the registration number will be allowed on roads on odd dates and those with even last digit will on even dates.

Given an integer array a[], contains the last digit of the registration number of N vehicles traveling on date D(a positive integer). The task is to calculate the total fine collected by the traffic police department from the vehicles violating the rules.

**Note :** For violating the rule, vehicles would be fined as X Rs.

**Example 1:**

**Input :**

4 -> Value of N

{5,2,3,7} -> a[], Elements a[0] to a[N-1], during input each element is separated by a new line

12 -> Value of D, i.e. date

200 -> Value of x i.e. fine

**Output :**

600 -> total fine collected

**Explanation:**

Date D=12 means , only an even number of vehicles are allowed.

Find will be collected from 5,3 and 7 with an amount of 200 each.

Hence, the output = 600.

**Example 2:**

**Input :**

5 -> Value of N

{2,5,1,6,8} -> a[], elements a[0] to a[N-1], during input each element is separated by new line

3 -> Value of D i.e. date

300 -> Value of X i.e. fine

Output :

900 -> total fine collected

**Explanation:**

Date D=3 means only odd number vehicles with are allowed.

Find will be collected from 2,6 and 8 with an amount of 300 each.

Hence, the output = 900

**Constraints:**

- 0<N<=100
- 1<=a[i]<=9
- 1<=D <=30
- 100<=x<=5000

The input format for testing

The candidate has to write the code to accept 4 input(s).

First input – Accept for N(Positive integer) values (a[]), where each value is separated by a new line.

Third input – Accept value for D(Positive integer)

Fourth input – Accept value for X(Positive integer )

The output format for testing

The output should be a positive integer number (Check the output in Example 1, Example e) if no fine is collected then print ”0”.