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.
THANK YOU MAN
This helped me a lot. I'm using String instead of StringBuilder or StringBuffer. Now I changed it to StringBuffer and my code ran faster than before :) This can still be reduced to:
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int a0 = 0; a0 < t; a0++){
{
int n = in.nextInt();
StringBuilder strb=new StringBuilder();
for(int i=n;i>=0;i--)
{
if(i%3==0 && (n-i)%5==0)
{
int j=0;
for(j=0;j<i;j++)
strb.append("5");
for(int k=j;k<n;k++)
strb.append("3");
break;
}
}
if(strb.length()==0)
System.out.println("-1");
else
System.out.println(strb);
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and The Beast
You are viewing a single comment's thread. Return to all comments →
THANK YOU MAN This helped me a lot. I'm using String instead of StringBuilder or StringBuffer. Now I changed it to StringBuffer and my code ran faster than before :) This can still be reduced to: