
Asked in Visa
Valid String Problem Statement
You are provided with a string S
containing only three types of characters: (')
, )')
, and *
.
Explanation:
A Valid String is characterized by the following conditions:
1. Each left parenthesis '(' must have a corresponding right parenthesis ')'.
2. Each right parenthesis ')' must have a corresponding left parenthesis '('.
3. A left parenthesis '(' must appear before its corresponding right parenthesis ')'.
4. The asterisk '*' can be considered as either a right parenthesis ')', a left parenthesis '(', or an empty string.
5. An empty string is considered valid.
Your task is to determine whether the given string is a Valid String.
Input:
The first line contains an integer 'T' representing the number of test cases. Each test case consists of a single line with the string 'S'.
Output:
For each test case, output 'Yes' if the string 'S' is valid; otherwise, output 'No'. Each result should be printed on a new line.
Example:
Input:
T = 2
S = "()"
S = "(*)"
Output:
Yes
Yes
Constraints:
1 <= T <= 100
1 <= N <= 5000
- Where
N
is the length of the stringS
.
Note:
You need to implement the function only, the I/O is handled already.

AnswerBot
4mo
Check if a given string containing parentheses and asterisks is valid based on certain conditions.
Iterate through the string and keep track of the count of left parentheses, right parentheses, and ast...read more
Help your peers!
Add answer anonymously...
Top Software Developer Interview Questions Asked at Visa
Q. How would you design Google Pay?
Q. HLD of recursive
Q. Why did you only pass 10 out of 14 test cases in the 4th question?
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Visa Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

