This blog covers the TCS Digital Coding Questions that were asked on 29th September 2021 in the evening slot at 4 pm.
This is the third time when TCS Elevate Wings DCA is conducting the year 2021. Previously it was organized in the month of January and April.
Eligibility
Full-time active employees in C1 or below grades with a total relevant experience of up to 3 years as of 31st Aug 2021 with Technical Qualifications
- BE/B.Tech, ME/M.Tech
- B.Sc/BCA and equivalent qualifications
- M.Sc/MCA/MS and equivalent qualifications
Assessment Date: 27th to 30th Sep
Question 1 :
A man has money/coins in two different bags. He visits the market to buy some items. Bag A has N coins and bag B has M coins. The denominations of the money are given as array elements in a[] and b[]. He can buy products of by paying an amount which is an even number by choosing money from both the bags. The task here is to find the number of ways the man can buy items such that the product of money from both the bags is an even number.
The man has to pick one coin at least from each bag to make an even number product.
Example 1:
Input:
3- Value of N
3- Value of M
(1,2,3)-a[], Elements a[0] to a[N-1], where each input element is separated by new line
(5,6,7)b), Elements b[0] to b[N-1], where each input element is separated by new line
Output:
5-Number of ways
//Solution by technoname.com
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n1,n2;
cin>>n1;
cin>>n2;
int c=0;
vector<int> v1(n1),v2(n2);
for(int i=0;i<n1;i++)
cin>>v1[i];
for(int i=0;i<n2;i++)
cin>>v2[i];
for(int i=0;i<v1.size();i++)
{
for(int j=0;j<v2.size();j++)
{
if((v1[i]*v2[j])%2==0)
c++;
}
}
cout<<c;
return 0;
}
Question 2 :
There are 26 chairs that need to be arranged for a ceremony. The chairs are named from A to Z . Every chair should be arranged according to the ordinal number of the letter in the English alphabet. Due to some misunderstanding, the chairs are randomly arranged. Given a str, the task here is to find the number of chairs which are correctly placed as per the ordinal number of the letters as given below.
The same positions apply for both uppercase and lower case letters.
Example 1:
Input:
abcxyz — Value of str
Output: Number of chairs that are correctly placed as 3 per ordinal position of the letters of the English alphabet
Explanation :
From the inputs given above: Letters a, b and c are in the correct positions 1, 2, and 3, respectively Rest of the letters are not in the correct positions.
Hence, the output is 3.
Example 2:
Input:
abcxyzgh—Value of str
Output:
5 – Number of chairs that are correctly placed as per the ordinal position of the letters of the English alphabet.
Solution
//Solution by technoname.com
import java.util.Scanner;
public class Technoname
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
int count=1;
for(int i=1;i<str.length();i++)
{
if(str.charAt(i)==str.charAt(0)+i)
count++;
}
System.out.println(count);
}
}
Question numbers 1 and 2 were asked in the evening slot at 4 pm, 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
Thanks for reading this article so far. If you like this article, then please share it with your friends and colleagues. If you have any questions or feedback, then please drop a note.
You can also follow us on Twitter for daily updates.
2nd Question Python 3 –
def OrdinalChairs(s):
count = 0
for i in range(len(s)):
if ord(s[i]) == ord(s[0])+i:
count+=1
print(count)
string = str(input())
OrdinalChairs(string)
Good Efforts!
can question 1 be solve like this?
import java.util.*;
public class Bag{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
System.out.println(“Enter the value of m :”);
int m = sc.nextInt();
System.out.println(“Enter the value of m :”);
int n = sc.nextInt();
int [] a = new int[m];
int []b=new int[n];
int c1=0,c2=0;
for(int i=0;i<a.length;i++){
a[i]=sc.nextInt();
if(a[i]%2==0){
c1++;
}
}
for(int i=0;i<a.length;i++){
b[i]=sc.nextInt();
if(b[i]%2==0){
c2++;
}
}
/*System.out.println("number of even no in bag 1: "+c1);
System.out.println("number of odd no in bag 1: "+(m-c1));
System.out.println("number of even no in bag 2: "+c2);
System.out.println("number of odd no in bag 2: "+(n-c2)) ;*/
System.out.println("number of combination that user can pay in even no : "+((c1*c2)+((m-c1)*(n-c2))));
}
}
import java.util.*;
public class Bag{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
System.out.println(“Enter the value of m :”);
int m = sc.nextInt();
System.out.println(“Enter the value of m :”);
int n = sc.nextInt();
int [] a = new int[m];
int []b=new int[n];
int c1=0,c2=0;
for(int i=0;i<a.length;i++){
a[i]=sc.nextInt();
if(a[i]%2==0){
c1++;
}
}
for(int i=0;i<a.length;i++){
b[i]=sc.nextInt();
if(b[i]%2==0){
c2++;
}
}
/*System.out.println("number of even no in bag 1: "+c1);
System.out.println("number of odd no in bag 1: "+(m-c1));
System.out.println("number of even no in bag 2: "+c2);
System.out.println("number of odd no in bag 2: "+(n-c2)) ;*/
System.out.println("number of combination that user can pay in even no : "+((c1*c2)+((m-c1)*(n-c2))));
}
}
code in C for first one
#include
#include
int main ()
{
int a[100],b[100],i,j,n,m,c=0,sum;
scanf(“%d %d”,&m,&n);
for(i=0;i<m;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
sum=a[i]+b[j];
if(sum%2==0)
c++;
}
}
printf("%d",c);
return 0;
}
code in C for second question
#include
#include
int main ()
{
char a[100];
int n,l,i,c=0;
gets(a);
l=strlen(a);
for(i=0;i<=l;i++)
{
if(a[i]==a[0]+i)
c++;
}
printf("%d",c);
return 0;
}