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.
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int tc = in.nextInt();
while (tc-- > 0) {
getNumbr(in.nextInt());
}
in.close();
}
private static void getNumbr(int n) {
// TODO Auto-generated method stub
int n5 = 0, n3 = 0;
int nt = n;
while (nt % 3 != 0) {
nt -= 5;
n3 += 1;
if (nt < 3 && nt != 0) {
System.out.println("-1");
return;
}
}
n5 = nt / 3;
String s = "";
for (int i = 0; i < n5; ++i)
s += "555";
for (int i = 0; i < n3; ++i)
s += "33333";
for (int i = 0; i < s.length(); ++i)
System.out.print(s.charAt(i));
System.out.println();
}
could you please point out the inefficiency in printing in my case, as i am also getting timeout for 5-13.
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 →
could you please point out the inefficiency in printing in my case, as i am also getting timeout for 5-13.