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.

AnswerBot
1y

Find minimum number of * or # to make a string valid with equal number of * and #.

  • Count the number of * and # in the string.

  • Find the absolute difference between the counts.

  • Return the difference as the...read more

PrepInsta
author
2y
#include 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<
Help your peers!
Add answer anonymously...
TCS Assistant System Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter