0 like 0 dislike
12,322 views

All tcs nqt codes for all batches available in group @tcs_nqt_ans : https://telegram.im/@tcs_nqt_ans

edited | 12,322 views

0 like 0 dislike
All TCS NQT Coding Solutions for year 2022 can be found here : https://www.desiqna.in/tag/tcs_nqt
by Expert (110,880 points)
0 like 0 dislike

### TCS 2022 Coding Question Day 2 Slot 1 – Question 2

At a fun fair, a street vendor is selling different colours of balloons. He sells N number of different colours of balloons (B[]). The task is to find the colour (odd) of the balloon which is present odd number of times in the bunch of balloons.

Note: If there is more than one colour which is odd in number, then the first colour in the array which is present odd number of times is displayed. The colours of the balloons can all be either upper case or lower case in the array. If all the inputs are even in number, display the message “All are even”.

Example 1:

• 7  -> Value of N
• [r,g,b,b,g,y,y]  -> B[] Elements B[0] to B[N-1], where each input element is sepārated by ṉew line.

Output :

• r -> [r,g,b,b,g,y,y]  -> “r” colour balloon is present odd number of times in the bunch.

Explanation:

From the input array above:

• r: 1 balloon
• g: 2 balloons
• b:  2 balloons
• y : 2 balloons

Hence , r is only the balloon which is odd in number.

Example 2:

Input:

• 10 -> Value of N
• [a,b,b,b,c,c,c,a,f,c] -> B[], elements B[0] to B[N-1] where input each element is separated by new line.

Output :

b-> ‘b’ colour balloon is present odd number of times in the bunch.

Explanation:

From the input array above:

• a: 2 balloons
• b: 3 balloons
• c: 4 balloons
• f: 1 balloons

Here, both ‘b’ and ‘f’ have odd number of balloons. But ‘b’ colour balloon occurs first.

Hence , b is the output.

Input Format for testing

The candidate has to write the code to accept: 2 input

• First input: Accept value for number of N(Positive integer number).
• Second Input : Accept N number of character values (B[]), where each value is separated by a new line.

Output format for testing

The output should be a single literal (Check the output in example 1 and example 2)

Constraints:

• 3<=N<=50
• B[i]={{a-z} or {A-Z}}
```import java.util.*;

class Solution

{

public static void main (String[]args)

{

Scanner sc = new Scanner (System.in);

int n = sc.nextInt ();

char arr[] = new char[n];

for (int i = 0; i < n; i++)

arr[i] = sc.next ().charAt (0);

int lower[] = new int[26];

int upper[] = new int[26];

for (int i = 0; i < n; i++)

{

if ((arr[i] >= 'A') && (arr[i] <= 'Z'))

upper[arr[i] - 'A']++;

else if ((arr[i] >= 'a') && (arr[i] <= 'z'))

lower[arr[i] - 'a']++;

}

boolean flag = false;

char ch = '\0';

for (int i = 0; i < n; i++)

{

if ((arr[i] >= 'A') && (arr[i] <= 'Z'))

{

if (upper[arr[i] - 'A'] % 2 == 1)

{

ch = (char) (arr[i]);

flag = true;

break;

}

}

else if ((arr[i] >= 'a') && (arr[i] <= 'z'))

{

if (lower[arr[i] - 'a'] % 2 == 1)

{

ch = (char) (arr[i]);

flag = true;

break;

}

}

}

if (flag == true)

System.out.println (ch);

else

System.out.println ("All are even");

}

}```

by Expert (110,880 points)
0 like 0 dislike

### TCS 2022 Coding Question Day 2 Slot 1 – Question 1

A party has been organised on cruise. The party is organised for a limited time(T). The number of guests entering (E[i]) and leaving (L[i]) the party at every hour is represented as elements of the array. The task is to find the maximum number of guests present on the cruise at any given instance within T hours.

Example 1:

Input :

• 5    -> Value of T
• [7,0,5,1,3]  -> E[], Element of E[0] to E[N-1], where input each element is separated by new line
• [1,2,1,3,4]   -> L[], Element of L[0] to L[N-1], while input each element is separate by new line.

Output :

8     -> Maximum number of guests on cruise at an instance.

Explanation:

• 1st hour:

Entry : 7 Exit: 1

No. of guests on ship : 6

2nd hour :

Entry : 0 Exit : 2

No. of guests on ship : 6-2=4

Hour 3:

Entry: 5 Exit: 1

No. of guests on ship : 4+5-1=8

Hour 4:

Entry : 1 Exit : 3

No. of guests on ship : 8+1-3=6

Hour 5:

Entry : 3 Exit: 4

No. of guests on ship: 6+3-4=5

Hence, the maximum number of guests within 5 hours is 8.

Example 2:

Input:

4  -> Value of T

[3,5,2,0]   -> E[], Element of E[0] to E[N-1], where input each element is separated by new line.

[0,2,4,4]    -> L[], Element of L[0] to L[N-1], while input each element in separated by new line

Output:

6

Cruise at an instance

Explanation:

Hour 1:

Entry: 3 Exit: 0

No. of guests on ship: 3

Hour 2:

Entry : 5 Exit : 2

No. of guest on ship: 3+5-2=6

Hour 3:

Entry : 2 Exit: 4

No. of guests on ship: 6+2-4= 4

Hour 4:

Entry: 0  Exit : 4

No. of guests on ship : 4+0-4=0

Hence, the maximum number of guests within 5 hours is 6.

The input format for testing

The candidate has to write the code to accept 3 input.

First input- Accept  value for number of T(Positive integer number)

Second input- Accept T number of values, where each value is separated by a new line.

Third input- Accept T number of values, where each value is separated by a new line.

The output format for testing

The output should be a positive integer number or a message as given in the problem statement(Check the output in Example 1 and Example 2)

Constraints:

• 1<=T<=25
• 0<= E[i] <=500
• 0<= L[i] <=500
```import java.util.*;

class Solution

{

public static void main (String[]args)

{

Scanner sc = new Scanner (System.in);

int t = sc.nextInt ();

int e[] = new int[t];

int l[] = new int[t];

for (int i = 0; i < t; i++)

e[i] = sc.nextInt ();

for (int i = 0; i < t; i++)

l[i] = sc.nextInt ();

int max = 0, sum = 0;

for (int i = 0; i < t; i++)

{

sum += e[i] - l[i];

max = Math.max (sum, max);

}

System.out.println (max);

}

}```

by Expert (110,880 points)
0 like 0 dislike

### TCS 2022 Coding Question Day 1 Slot 2 – Question 2

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 prpeinzta 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.

Example 1:

Input :

3   -> Value of R(row)

3 -> value of C(column)

[0 1 0 1 1 0 1 1 1] -> Elements of the array M[R][C] where each element is separated by new line.

Output :

3  -> Row 3 has maximum number of 1’s

Example 2:

input :

4 -> Value of R(row)

3 -> Value of C(column)

[0 1 0 1 1 0 1 0 1 1 1 1] -> Elements of the array M[R][C]

Output :

4  -> Row 4 has maximum number of 1’s

```

#include <bits/stdc++.h>

using namespace std;

int main()

{

int r,c,a,sum=0,m=INT_MIN,in=0;

cin>>r>>c;

for(int i=0;i<r;i++)

{

for(int j=0;j<c;j++)

{

cin>>a;

sum+=a;

}

if(sum>m)

{

m=sum;

in=i+1;

}

sum=0;

}

cout<<in;

}```

by Expert (110,880 points)
0 like 0 dislike

### TCS Coding Question 2022 Day 1 Slot 2 – Question 1

Given an integer array Arr of size N the task is to find the count of elements whose value is greater than all of its prior elements.

Note : 1st element of the array should be considered in the count of the result.

For example,

Arr[]={7,4,8,2,9}

As 7 is the first element, it will consider in the result.

8 and 9 are also the elements that are greater than all of its previous elements.

Since total of  3 elements is present in the array that meets the condition.

Hence the output = 3.

Example 1:

Input

5 -> Value of N, represents size of Arr

7-> Value of Arr[0]

4 -> Value of Arr[1]

8-> Value of Arr[2]

2-> Value of Arr[3]

9-> Value of Arr[4]

Output :

3

Example 2:

5   -> Value of N, represents size of Arr

3  -> Value of Arr[0]

4 -> Value of Arr[1]

5 -> Value of Arr[2]

8 -> Value of Arr[3]

9 -> Value of Arr[4]

Output :

5

Constraints

• 1<=N<=20
• 1<=Arr[i]<=10000
```#include <bits/stdc++.h>

using namespace std;

int main()

{

int n,c=0,a,m=INT_MIN;

cin>>n;

while(n--)

{

cin>>a;

if(a>m)

{

m=a;

c++;

}

}

cout<<c;

}```

by Expert (110,880 points)
0 like 0 dislike

### TCS NQT Coding Question 2022 – September Day 1 – Slot 1

Problem Statement – Given a string S(input consisting) of ‘*’ and ‘#’. The length of the string is variable. The task is to find the minimum number of ‘*’ or ‘#’ to make it a valid string. The string is considered valid if the number of ‘*’ and ‘#’ are equal. The ‘*’ and ‘#’ can be at any position in the string.

Note : The output will be a positive or negative integer based on number of ‘*’ and ‘#’ in the input string.

• (*>#): positive integer
• (#>*): negative integer
• (#=*): 0

Example 1:

Input 1:

• ###***   -> Value of S

Output :

• 0   → number of * and # are equal
```#include <bits/stdc++.h>

using namespace std;

int main()

{

string s;

int a=0,b=0;

getline(cin,s);

for(auto i:s)

if(i=='#') a++;

else if(i=='*') b++;

cout<<b-a;

}```

by Expert (110,880 points)
0 like 0 dislike

### TCS NQT Coding Question 2022 – September Day 1 – Slot 1

Problem Statement – An automobile company manufactures both a two wheeler (TW) and a four wheeler (FW). A company manager wants to make the production of both types of vehicle according to the given data below:

• 1st data, Total number of vehicle (two-wheeler + four-wheeler)=v
• 2nd data, Total number of wheels = W

The task is to find how many two-wheelers as well as four-wheelers need to manufacture as per the given data.

Example :

Input :

• 200  -> Value of V
• 540   -> Value of W

Output :

• TW =130 FW=70

Explanation:

130+70 = 200 vehicles

(70*4)+(130*2)= 540 wheels

Constraints :

• 2<=W
• W%2=0
• V<W

Print “INVALID INPUT” , if inputs did not meet the constraints.

The input format for testing

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

• First Input line – Accept value of V.
• Second Input line- Accept value for W.

The output format for testing

• Written program code should generate two outputs, each separated by a single space character(see the example)
• Additional messages in the output will result in the failure of test case.
```#include <bits/stdc++.h>

using namespace std;

int main ()

{

int v, w;

cin >> v >> w;

float x = ((4 * v) - w) / 2;

if ((w & 1) || w < 2 || w <= v)

{

cout << "INVALID INPUT";

return 0;

}

cout << "TW=" << x << " " << "FW=" << v - x;

}```

by Expert (110,880 points)