BubbleBrackets
You are given an array of n strings, and each string contains only open and closed brackets.
Find out if those strings can be sorted in such a way that after the concatenation of all strings, a valid arrangement of brackets is achieved (like as in a math expression after removing all other characters).
InputThe first line contains the positive integer n (1≤ n ≤100,000), the number of strings. Each of the next n lines contains a sequence of ‘( and ‘)’ characters, up to the end of the line. Total number of all characters in all strings does not exceed 10,000,000 (ten millions).
OutputThe output consists of one word: “yes” (without quotes) if the required arrangement of strings exists; “no” if it doesn’t exist
Input:
3
(()
(
))
Output:
yes
Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.