Sherlock and The Beast

  • + 1 comment

    it looks like java cannot print a 100000 char string in one shot(i know that the string is printed but its just not visible and therefore cannot be read by hackerrank).if i loop the printing statement and print on the same line then hackeerrank doesnt accept my answer although the output is the same. it makes sense because i am executing multiple print stements for the same input. how do i solve this ?0-3 test are correct 4-13 always "Time out" and 14 is a runtime error(I'll look into it after i fix this :))and the 15 test is corrent.

    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
    public static void main(String[] args) {
    
          Scanner in = new Scanner (System.in);
    
          int number = in.nextInt();
          int temp=0;
          String s= "";
    
          for (int i=0;i<number;i++){
              temp = in.nextInt();
              int five =temp;
              int three =0;
              s="";
              for(int j =0;j<temp;j++){s+="5";}
    
              for (int k=0;k<temp;k++){
                if (temp%3!=0&five%3!=0&temp>=5&five>0){
    
                  three+=5;
                  five-=5;
                }else{break;}    
              }
           if (temp>=3&five%3==0){
               s=s.substring(0,five);
               for(int j=0;j<three;j+=5){
                   s+="33333";
               }
               System.out.println(s);
           }else{System.out.println("-1");}          
        }
      }
    }