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
Program :
#TCS NQT Coding Question 2022 –
September Day 1 – Slot 1
s=input("Enter a String : ")
a=0
b=0
for i in s:
if i=='*':
a+=1
elif i=='#':
b+=1
print(a-b)
For execution and output so check the
video :
Comments
Post a Comment