Encoded String(DECODEIT)Solution — Codechef JanuaryLong Challenge

  • Among (a,b,c,d,e,f,g,h || i,j,k,l,m,n,o,p), j appears in the second half. So the first bit of its encoding is 1.
  • Now, among (i,j,k,l || m,n,o,p), j appears in the first half. So the second bit of its encoding is 0.
  • Now, among (i,j || k,l), j appears in the first half. So the third bit of its encoding is 0.
  • Now, among (i || j), j appears in the second half. So the fourth and last bit of its encoding is 1.

Input:

  • The first line of the input contains an integer T, denoting the number of test cases.
  • The first line of each test case contains an integer N, the length of the encoded string.
  • The second line of each test case contains the encoded string S.

Output:

Constraints

  • 1≤T≤10
  • 4≤N≤105
  • The length of the encoded string is a multiple of 4.
  • 0≤Si≤1

Subtasks

  • 100 points : Original constraints.

Sample Input:

3
4
0000
8
00001111
4
1001

Sample Output:

a
ap
j

Explanation:

  • Sample Case 1 :
  • Sample Case 2 :
  • Sample Case 3 :
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
while(n--!=0){
int size=Integer.parseInt(br.readLine());
String str=br.readLine();

String s="";
String ans="";
for(int i=0;i<size;i=i+4){
if((i+4)==size)
s=str.substring(i);
else
s=str.substring(i,i+4);

int start=0;
int mid=0;

String arr="abcdefghijklmnop";
int end=arr.length();
String a="";
for(int j=0;j<s.length();j++){

if(s.charAt(j)=='0'){
mid=(start+end)/2;
a=arr.substring(start,mid);
end=mid;
}
else{
mid=(start+end)/2;
if(end==16)
a=arr.substring(mid);
else
a=arr.substring(mid,end);
start=mid;
}
}
ans=ans+a;
}
System.out.println(ans);
}
}
}

--

--

--

Software Developer ,currently pursuing B.Tech in Information Technology. Electronic Dance Music is love.Also like all phone related technologies

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Configure VLAN Tagging on top of LACP Network Bonding using nmcli

Understanding Custom Roms

Setup to ping google but not able to ping Facebook..!!

Integration of BrowserStack with Jenkins to run cypress test cases

Delta: A Data Synchronization and Enrichment Platform

- How to mint SolMushies -

Preparing for Professional Scrum Master II

Create & Merge PDF Files in Memory Stream Using BytesIO in Python

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anubhav Mishra

Anubhav Mishra

Software Developer ,currently pursuing B.Tech in Information Technology. Electronic Dance Music is love.Also like all phone related technologies

More from Medium

VERY Basic Differences Between Java and JavaScript-Arrays

Why you should not use “currentTimeMillis” when you calculate elapsed time?

Role of start() and run() in Multithreading in Java

Polymorphism in JAVA