#K71417. Avoiding Consecutive Ones by Deleting One Character

    ID: 33527 Type: Default 1000ms 256MiB

Avoiding Consecutive Ones by Deleting One Character

Avoiding Consecutive Ones by Deleting One Character

You are given a binary string S of length N. Your task is to determine whether it is possible to delete exactly one character from S such that the resulting string does not contain any two consecutive '1's.

If the original string already does not contain two consecutive '1's, you may still delete one character arbitrarily and the resulting string will remain valid.

Formally, let \(S\) be a string of length \(N\) consisting of characters '0' and '1'. Determine if there exists an index \(i\) (\(1 \le i \le N\)) such that when the \(i\)-th character is removed, the new string S' does not have any occurrence of "11". If such an index exists, print YES, otherwise print NO.

Example:

For example, if \(S = "110"\), by deleting the first character, we get "10" which does not contain consecutive ones, so the answer is YES.

inputFormat

The input is read from standard input (stdin) and has the following format:

T
N1
S1
N2
S2
... 
NT
ST

Here, T denotes the number of test cases. For each test case:

  • The first line contains an integer N (the length of the binary string).
  • The second line contains the binary string S of length N.

outputFormat

For each test case, output a single line containing either YES if it is possible to delete exactly one character such that the resulting string does not contain any two consecutive '1's, or NO otherwise. The answers should be printed to standard output (stdout).

## sample
3
3
110
4
1010
5
11111
YES

YES NO

</p>