Problem description. Vipul is a hardworking super-hero who maintains the bracket ratio…
- User
Problem description. Vipul is a hardworking super-hero who maintains the bracket ratio of all the strings in the world. Recently he indulged himself in saving the string population so much that he lost his ability for checking brackets (luckily, not permanently ).Being his super-hero friend help him in his time of hardship. Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single string S denoting the string to be checked.
Output
For each test case, output a single line printing "YES" or "NO" (without " " and in uppercase only) , denoting if the brackets in the given string is balanced or not .
Constraints
1 ≤ T ≤ 10 1 ≤ length of S ≤ 60
Example Input: 3 ((())) (())() ()(()
Output: YES YES NO
Explanation Example is self-explanatory.
Assistant
pythonT = int(input()) for _ in range(T): s = input().strip() stack = [] valid = True for char in s: if char == '(': stack.append(char) elif char == ')': if not stack: valid = False break stack.pop() print("YES" if valid and not stack else "NO")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.