Balanced Parentheses Check

Given a string STR consisting solely of the characters '{', '}', '(', ')', '[', and ']', determine whether the parentheses are balanced.

Input:

The first line contains an integer 'T' representing the number of test cases. Each of the following T lines contains a string representing a test case.

Output:

For each test case, output 'YES' if the expression is balanced and 'NO' otherwise. Each result should be printed on a new line.

Example:

Input:

3
{}[()]
{[}]
({[()]})

Output:

YES
NO
YES

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 10^5
  • Where N is the length of the input string or expression.

Note: You don't need to print anything yourself; just implement the function to solve the problem.

Be the first one to answer
Add answer anonymously...
Snapdeal Software 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