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.

AnswerBot
4mo

Implement a function to check if parentheses in a string are balanced.

  • Use a stack to keep track of opening parentheses and pop when a closing parenthesis is encountered.

  • If the stack is empty when a cl...read more

Help your peers!
Select
Add answer anonymously...

Snapdeal Software Engineer interview questions & answers

A Software Engineer was asked Q. Given a binary tree, return the vertical sum of the tree.
A Software Engineer was asked Q. How many rectangles/squares are there on a chessboard?
A Software Engineer was asked Q. How would you dynamically calculate the top 10 most frequent words on Facebook w...read more

Popular interview questions of Software Engineer

A Software Engineer was asked Q1. Given an array, find a pair of elements.
A Software Engineer was asked Q2. Given a binary tree, return the vertical sum of the tree.
A Software Engineer was asked Q3. How many rectangles/squares are there on a chessboard?
Snapdeal Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits