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.
Iterative is a little hard to get but here is my way:
String e = new String("");
int r= (int)Math.sqrt(s.length());
if(r*r!=s.length()) r++;
for(int i=0;i<r;i++){
int j=0;
while(j*r+i<s.length()){
e = e+s.charAt(j*r+i);
j++;
}
e=e+" ";
}
return e;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Encryption
You are viewing a single comment's thread. Return to all comments →
Iterative is a little hard to get but here is my way:
String e = new String(""); int r= (int)Math.sqrt(s.length()); if(r*r!=s.length()) r++; for(int i=0;i<r;i++){ int j=0; while(j*r+i<s.length()){ e = e+s.charAt(j*r+i); j++; } e=e+" "; } return e;