Problem Statement:

Kulyash believes in equality.
Given an integer N, output a binary string of length N such that:

The count of 01 subsequences in the string is equal to the count of 10 subsequences;
The string has at least one occurrence of 0 as well as 1.
If multiple such strings exist, print any. Also, it is guaranteed that corresponding to the given input, an answer always exists.

Input Format:

First line will contain T, number of test cases. Then the test cases follow.
Each test case contains of a single line of input, an integer N – the length of the binary string.

Output Format:

For each test case, output any binary string of length N satisfying the given conditions.

Constraints:

1≤T≤100
3≤N≤1000
Subtasks

Sample Input:

2
4
3

Sample Output:

1001
010

Explanation
Test case 1: A binary string satisfying both the conditions is 1001. The count of 01 as well as 10 subsequences in the string is 2.

Test case 2: A binary string satisfying both the conditions is 010. The count of 01 as well as 10 subsequences in the string is 1.

Solution:

				
					/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while (t-->0){
		    int n=sc.nextInt();
		    int i=0;
		    int j=n-1;
		    String str="";
		    while(i<=j){
		        if(i%2==0){
		            if(i==j){
		                str=str.substring(0,i)+"1"+str.substring(i);
		            }
		            else{
		            str="1"+str+"1";
		            }
		        }
		        else{
		            if(i==j){
		                str=str.substring(0,i)+"0"+str.substring(i);
		            }
		            else{
		            str="0"+str+"0";
		            }      
		        }
		        i++;
		        j--;
		    }
		    System.out.println(str);
		} 
		
	
		
	
	}
}
				
			

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published.