We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.util.*;publicclassSolution{publicstaticvoidmain(String[]args){Scannersc=newScanner(System.in);inttc=sc.nextInt();for(intt=0;t<tc;t++){intn=sc.nextInt();int[]a=newint[n];int[]b=newint[n];int[]c=newint[n+n];//to merge both the streamStrings1=sc.next();Strings2=sc.next();intcount=0;for(inti=0,j=0;i<n;i++,j+=2){if(s1.charAt(i)=='0')a[i]=0;elsea[i]=1;if(s2.charAt(i)=='0')b[i]=0;elseb[i]=1;if(a[i]==1)count++;if(b[i]==1)count++;//merging both the stream in alternate fashion c[j]=a[i];c[j+1]=b[i];}//if No of 1's is Even Then solution May Exist if(count%2==0){for(inti=1;i<n+n;i++)if(c[i-1]==0&&c[i]==0)//for '--' patternc[i-1]=c[i]=1;elseif(i!=1&&c[i]==0&&c[i-2]==0)//for '/' pattern c[i-2]=c[i]=1;intflag=0;for(inti=0;i<n+n;i++)//searching for 0 {if(c[i]==0){flag=1;break;}}if(flag==0)System.out.println("YES");elseSystem.out.println("NO");}elseSystem.out.println("NO");}}}
Note that This Can be Optimized further but here no need as n<=10 is given xD
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Hexagonal Grid
You are viewing a single comment's thread. Return to all comments →
Does Any Simpler Solution Exist Than This ??:
Note that This Can be Optimized further but here no need as n<=10 is given xD