In-game Chat (Codeforces 1465A)
Tags: Implement, strings

You have been assigned to develop a filter for bad messages in the in-game chat. A message is a string $$$S$$$ of length $$$n$$$, consisting of lowercase English letters and characters ')'. The message is bad if the number of characters ')' at the end of the string strictly greater than the number of remaining characters. For example, the string ")bc)))" has three parentheses at the end, three remaining characters, and is not considered bad.

Input: The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 100$$$). Description of the $$$t$$$ test cases follows.The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$). The second line of each test case contains a string $$$S$$$ of length $$$n$$$, consisting of lowercase English letters and characters ')'.

Output: For each of $$$t$$$ test cases, print "Yes" if the string is bad. Otherwise, print "No".You can print each letter in any case (upper or lower).


Sample Inputs:
5
2
))
12
gl))hf))))))
9
gege)))))
14
)aa))b))))))))
1
)

Sample Outputs:
Yes
No
Yes
Yes
Yes

Solution (Python):
for _ in range(int(input())):
    n = int(input())
    s = input().rstrip(')')
    if len(s) < n / 2:
        print('YES')
    else:
        print('NO')

Solution (Python):
t = int(input())
if t >= 1 and t <= 100:
    for i in range(t):
        x = 0
        n = int(input())
        s = input()
        if (n >= 1 and n <= 100) and len(s) == n:
            for i in range(len(s) - 1, -1, -1):
                if ord(s[i]) == 41 or (ord(s[i]) >= 97 and ord(s[i]) <= 122):
                    if ord(s[i]) != 41:
                        break
                    else:
                        x += 1
        a = len(s) - x
        if x > a:
            print('Yes')
        else:
            print('No')

Solution (Python):
for i in range(int(input())):
    n = int(input())
    s = input()
    temp = []
    for j in s[-1::-1]:
        if j != ')':
            break
        else:
            temp.append(j)
    if len(temp) > len(s) - len(temp):
        print('Yes')
    else:
        print('No')