PerMEXuation

 You are given an integer 

N and a (0-indexed) binary string A having length N+1.

Find any permutation P of 0,1,2,...,N1 (or determine that it does not exist) that satisfies the following conditions for all i (0iN):

  • if Ai=0: No contiguous segment of P has mex equal to i
  • if Ai=1: There exists at least one contiguous segment of P that has mex equal to i

If multiple permutations exist that satisfy the given conditions, print any.

Note: mex of a segment is the smallest non-negative number that does not occur in that segment.

Input Format

  • The first line contains the number of test cases T. Description of the test cases follows.
  • The first line of each test case contains a single integer N.
  • The second line of each test case contains the binary string A of length N+1.

Output Format

For each test case print :

  • Yes if there exists a permutation P that satisfies the conditions described in the statement, followed by the permutation P in the next line (If multiple permutations exist that satisfy the given conditions, print any).
  • No otherwise.

You may print each character of Yes and No in uppercase or lowercase (for example, yesyEsYES will be considered identical).

Constraints

  • 1T104
  • 2N3105
  • |A|=N+1
  • It is guaranteed that the sum of N over all test cases does not exceed 3105.

Sample Input 1 

4
2
111
5
110100
5
110101
7
11100111

Sample Output 1 

Yes
0 1
No
Yes
0 2 1 4 3
Yes
0 1 3 4 2 5 6

Explanation

Test case-1: One of the possible permutations satisfying the given conditions is [0,1] because:

  • mex([1])=0. Therefore the condition is satisfied for i=0.
  • mex([0])=1. Therefore the condition is satisfied for i=1.
  • mex([0,1])=2. Therefore the condition is satisfied for i=2.

Test case-2: It can be proven that no permutation exists that satisfies the given conditions.

Test case-3: One of the possible permutations satisfying the given conditions is [0,2,1,4,3] because:

  • mex([2])=0. Therefore the condition is satisfied for i=0.
  • mex([0,2])=1. Therefore the condition is satisfied for i=1.
  • There does not exist any segment with mex=2. Therefore the condition is satisfied for i=2.
  • mex([0,2,1])=3. Therefore the condition is satisfied for i=3.
  • There does not exist any segment with mex=4. Therefore the condition is satisfied for i=4.

Comments

Popular posts from this blog

Walmart Sparkplug 2022 | 150 students will be selected for summer internship | ₹1-1.1 lakh monthly

Flipkart Runway: Season 3 | 2025 | Internship

Python for Data Science NPTEL Assignment Solutions Week 4 2022

GATE 2022 Answer Key Release Date Announced; Details Here