# TCS Coding Questions 2022 Day 2 Slot 1

## Coding Question 2 for 2022 (September slot)

### TCS 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");  }}`

### 2 comments on “TCS Coding Questions 2022 Day 2 Slot 1”

• Vishnukant

x=int(input())
y=list(input().split())
m=0
n=[]
#creating unique element list
for i in y:
if i not in n:
n.append(i)

#for cheking how much even element in list
for i in n:
if y.count(i)%2==0:
m=m+1

if m==len(n):
print(“All even”)
exit()

for j in n:
if y.count(j)%2!=0:
print(j,end=” “)

// c++ code by subhradip barik
#include
using namespace std;
int main()
{
int size = 10;
vector odd;
map data;
for(int i=0;i> in;
data[in]++;
}
for(auto pr : data)
{
cout<< pr.first<<" "<<pr.second<<endl;
if(pr.second % 2 != 0)
{
odd.push_back(pr.first);
}
}
if(odd.size()== 0)
{
cout<<"all are even"<<endl;
return 0;
}
cout<<odd[0]<<endl;
return 0;

return 0;
}