X
- Placement Papers
- What is TCS NQT?
- How To Apply
- Foundation Section
- Aptitude Questions
- English Verbal
- Reasoning Ability
- Traits(Psychometric)
- Advanced Section
- Advanced Quantitative Ability
- Advanced Reasoning Ability
- Advanced Coding
- Coding Questions
- Syllabus 2023
- Recruitment Process
- Registration Process
- Eligibility Criteria
- How to prepare for TCS NQT?
- Interview Questions
- Hiring Process












TCS Coding Question 2 Day 1 Slot 1
Coding Question 2 for 2022 (September slot)
In this article, we will discuss about the TCS Coding Question which is asked in the TCS placement test. This type of Coding Questions will help you to crack your upcoming TCS exam as well as during your inteview process.


TCS Coding Question Day 1 Slot 1 – Question 2
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
C++
#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;
}
Java
import java.util.*;
public class Solution
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
String str=sc.next();
int count1=0,count2=0;
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)=='*')
count1++;
else if(str.charAt(i)=='#')
count2++;
}
System.out.println(count1-count2);
}
}
Python
s=input()
a=0
b=0
for i in s:
if i=='*':
a+=1
elif i=='#':
b+=1
print(a-b)
public class Question{
public static void main(String[] args) {
System.out.println(“Enter String:”);
Scanner sc=new Scanner(System.in);
String input=sc.nextLine();
int count1=0,count2=0;
for(int i=0;icount2)
{
System.out.println(“Positive integer”);
}
else
{
System.out.println(“negative integer”);
}
}
……………………….THE FOLLOWING ANSWER WILL ONLY CLEARR YOUR TEST CASES IN NQT EXAM……………………………..BY ABHISHEK PATIL
n=str(input())
m=str(input())
if len(n)==len(m):
print(“0”)
if len(n)>len(m):
print(len(n)-len(m))
if len(n)len(m):
print(len(n)-len(m))
if len(n)>len(m):
print(len(n)-len(m))
n=str(input())
m=str(input())
if len(n)==len(m):
print(“0”)
if len(n)>len(m):
print(len(n)-len(m))
if len(n)len(m):
print(len(n)-len(m))
if len(n)>len(m):
print(len(n)-len(m))
n=str(input())
m=str(input())
if len(n)==len(m):
print(“0”)
if len(n)>len(m):
print(len(n)-len(m))
if len(n)len(m):
print(len(n)-len(m))
if len(n)>len(m):
print(len(n)-len(m))
rah = “####*****”
raj = rah.count(“#”)
ram = rah.count(“*”)
if(raj>ram):
print(“Positive integer”)
elif(raj==ram):
print(“0”)
else:
print(“Negative integer”)
rah = “###***”
raj = rah.count(“#”)
ram = rah.count(“*”)
if(raj>ram):
print(“Positive integer”)
elif(raj==ram):
print(“0”)
else:
print(“Negative integer”)