# TCS DCA Questions Solved: 30 Sept 2021 This blog covers the TCS DCA (Digital Capability Assessment) Coding Questions that were asked on 30th September 2021 in the morning slot at 11 am.

This is the third time when TCS Elevate Wings DCA is conducting the year 2021. Previously TCS DCA was organized in the month of January and April.

## Question 1 :

In the game of scrabble, in order to avoid over-usage of the same letters in any word, Mario is trying to calculate if a letter appears more than three times in any word and wants to discard such words. In order to assist Mario, write a program to identify the number of times the most repeating letter would appear within any word. If the output number is more than three, Mario shall discard such words and choose another word for the game.

Example 1:
trumpet –Value of String input
Output:
2-Highest number of repeating letters in the word “trumpet”

Explanation: In the word “trumpet”, the highest repeating letter is ‘t’ repeated 2 times

Example 2:
Input: reiterate – Value of String
Output: 3- The highest number of repeating letters in the word reiterate.
Explanation: The word “reiterate” has 3 occurrences of the letter the rest of the letters appear only once

Constraints:

str = (a-z)
The input format for testing:
The candidate has to write the code to accept 1 input.
Accept a single string value (lowercase 301016 alphabets).
The output format for testing:
• The output should be a positive integer number (check the output in Example 1 and Example 2).
• The system does not allow any kind of hard-coded input value/values.
• The written program code by the candidate will be verified against the inputs which are supplied from the system.

## Solution in C

``````// Solution by Technoname.com
#include <stdio.h>
#include <string.h>
int main ()
{
char str;
char freq ={0};
scanf("%s",str);
int i, max;
int count = 0;
max=0;

for(int i=0;str[i]!='\0';i++)
{
freq[str[i]]++;
}
for(int i=0;str[i]!='\0';i++)
{
if(freq[str[i]]>max)
{
max =freq[str[i]];
}
}
printf("%d",max);

}``````

## Solution in Java

``````// Solution by Technoname.com

import java.util.Scanner;

class Technoname
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
char[] freq = new char;
int max =0;
int count = 0;

for(int i=0;i<str.length();i++)
{
freq[str.charAt(i)]++;
}
for(int i=0;i<str.length();i++)
{
if(freq[str.charAt(i)] >max)
{
max =freq[str.charAt(i)];
}
}

System.out.println(max);

}
}``````

The above type of question is asked multiple times in various technical rounds, you can check them out as well.

If you know any other way to solve the above problem then let us know in the comment section.

## Question 2 :

In an amusement park ticket booking system, reservations are stored in batches of user purchase as continuous ascending and nonrepeating reservation IDs. Reservation IDs are positive integers, set between 1 to 10000 and reset to 1 once 10000 is reached. Occasionally, it has been observed that for batches of booking between 3 and a maximum of 25 tickets by any user, one of the reservation IDs is omitted in the system. While a permanent fix is being provided by the software vendor, the task is to develop a program to identify the omitted reservation ID from such impacted batches. .

The tickets are always sorted in ascending order.

Example 1:
Input
:
7— Value of N
(1,2,4,5,6,7,8) –ar[], Elements ar to ar[N-1], where each input element is separated by a new line

Output : 3
Explanation:
In the Array arl], numbers are sorted in ascending numbers from 1 to 8, however, 3 is omitted.
Hence, the output is 3.

Example 2:
Input: 5 — Value of N
(23, 24, 25, 26, 28) — ar[], Elements ar to ar[N where input each element is separated by a new line
Output:
27 — Number 27 is omitted in the Array of sorted numbers.

Explanation:
In the Array arl], numbers are sorted in ascending numbers from 23 to 28, however, 27 is omitted.
Hence, the output is 27.

Input format for testing:

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

First Input-Accept value for N (positive integer)

Second Input – Accept N number of positive integer values(ar[]), where each value is separated by a new line.

The output format for testing:
• The output should be a positive integer number (check the output in Example 1 and Example 2).
• Additional messages in the output will cause the failure of test cases.
Instructions:
• The system does not allow any kind of hardcoded input value/values, The written program code by the candidate will be verified against the inputs which are supplied from the system

## Solution in Java

``````// Solution by Technoname.com

import java.util.Arrays;
import java.util.Scanner;

class Technoname
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int num=sc.nextInt();
int[] a=new int[num];
int c=0;

for(int i=0;i<num;i++)
{
a[i]=sc.nextInt ();

}

Arrays.sort(a);

for(int i=0;i<a.length-1;i++)
{
if(a[i+1]-a[i]!=1)
{
c=a[i+1]-1;
break;

}

}
System.out.println(c);

}
}``````

## Solution in Python

``````num = int(input())
l = []
res = int(input())

for i in range(num - 1):
k = int(input())
res += 1

if res != k:
print(res)
break``````

Question numbers 1 and 2 were asked in the morning slot at 11 am, if you know some other way to solve the question then please let us know in the comment section.

You can also check some other coding questions that were asked in the previous DCA (Digital capability Assessment) from here

Please check most asked programming questions of strings with examples by clicking here, after that you might get a deep knowledge about string operations, in short, it will be helpful in clearing the interview

### 13 responses to “TCS DCA Questions Solved: 30 Sept 2021”

1. Shubham says:

I tried to convert above scrable code into java
Here it is :-
import java.util.*;
public class shubham{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
char[] freq = new char;
int max;
int count = 0;
max=0;

for(int i=0;i<str.length();i++)
{
freq[str.charAt(i)]++;
}
for(int i=0;imax)
{
max =freq[str.charAt(i)];
}
}
System.out.println(max);
}
}

• Akshat Jain says:

Good efforts are done by you but some modifications need to be done, I have updated this post and uploaded code in Java as well, Please check it out.

2. Harish says:

n=int(input())
l=[]
for i in range(n):
a=int(input())
l.append(a)

#print(l)
m=[]
for i in range(l,l[-1]+1,1):
m.append(i)
#print(m)
for i in m:
if i not in l:
print(i)

3. kcoder says:

n=str(input())
d={}
for i in range(len(n)):
d[n[i]]=d.get(n[i],0)+1
for j in d:
if d[j]>=3:
break
else:
print(‘ok’)

4. kudu says:

n = int(input())
l1 = []
for i in range(n):
l1.append(int(input()))
l1.sort()
f=l1
for i in l1:
if(i!=f):
break
f+=1
print(f)

5. Kudu says:

l = input()
counts = []
for i in l:
counts.append(l.count(i))
counts.sort()
print(counts[-1])

6. Hrudini says:

#include
#include
int main ()
{
int a,i,n;
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=a;i<=a[n];i++)
{
if(i!=a[i])
{
printf("%d",i);
}
}
return 0;
}

can anyone please tell the modifications if you know as I can't get the output

7. Test says:

In problem it is stated that “Reservation IDs are positive integers, set between 1 to 10000 and reset to 1 once 10000 is reached.” so test case can be n=3 and a={9999,1,2} , so for this answer is 10000 but code is not working correct output. Please check this test case also.

• Akshat Jain says:

Okay good observation, will look into it.
Meanwhile, you can share your solution if any.

8. Test says:

Try this:

import java.util.*;

class HelloWorld {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
ArrayList al= new ArrayList();
for(int i=0;i<num;i++){
}
for(int i=1;i<al.size();i++) {
if(al.get(i)-al.get(i-1)!=1){
System.out.println(al.get(i-1)+1);
break;
}
}
}
}

9. prabal jain says:

1st question

s=input()
h=0
for i in s:
if s.count(i)>h:
h=s.count(i)
print(h)

• Akshat Jain says:

Good efforts.

10. Tabitha Fisher says:

2nd question

lis=list(map(int,input().split(“,”)))
cnt=lis
for i in lis:
if(cnt == i):
cnt += 1
else:
print(cnt)
break