X DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Valid String
Easy Accuracy: 41.43% Submissions: 3404 Points: 2

Given binary string str of size N the task is to check if the given string is valid or not. A string is called valid if the number of 0's equals the number of 1's and at any moment starting from the left of the string number 0's must be greater than or equals to the number of 1's.

Input:
1. The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
2. The first line of each test case contains a single integer N.
3. The next line contains a binary string without spaces.

Output: For each test case, print "yes" if string is valid. Otherwise, print "no" (without quotes)

Constraints:
1. 1 <= T <= 100

2. 1 <= N <= 104
3. '0' <= str[i] <= '1'

Example:
Input:

2
4
0011
3
001

Output:
yes
no

Explanation:
Test Case 1: String has an equal number of ones and zeros and at each index(starting from left) the number of occurrences of 0's is greater than or equals to the number of occurrences 1's.

### Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

#### My Submissions:  