✕
Stacks and QueuesCoding problems
Stacks and Queues: coding problems
Write a program that reads the input and prints the answer. Run checks it against every test, including hidden ones.
0 of 8 solved
A print shop writes each job ticket as a short string of brackets. A ticket is **valid** when every opening bracket is closed by its matching bracket, and the pairs nest without crossing. Check every ticket.
Each bracket is one of
( ) [ ] { }. A ticket never contains spaces.Input. The first line holds t, the number of tickets. Each of the next t lines holds one ticket, a non-empty string of brackets with no spaces. 1 <= t <= 1000 and each ticket has at most 300 characters.
Output. One line per ticket: `YES` if the ticket is valid, `NO` otherwise.
Example 1 input
4 ()[]{} ([{}]) (] ((Output
YES YES NO NO
Example 2 input
3 )) {[( []Output
NO NO YES