• + 1 comment

    In Java I was also getting a Timeout error, my guess is that because I was stroring the results (output) in a string , rather than printing them out one at a time.

    //Complete this code or write your own from scratch import java.util.; import java.io.;

    class Solution{ public static void main(String []argh){ Scanner in = new Scanner(System.in); int n = in.nextInt(); Map phoneBook= new HashMap();

        for(int i = 0; i < n; i++){
            String name = in.next();
            int phone = in.nextInt();
            // Write code here
            phoneBook.put(name,phone);
    
        }
    
        String results="";
        int searchNumber=0;
    
        while(in.hasNext()){
            String s = in.next();
            searchNumber++;
            // Write code here
            Integer num=phoneBook.get(s);
    
            if(num != null){
               System.out.print(s+"="+ num +"\n")  ;
            }
             else
               System.out.print("Not found\n")  ;
    
               //  results+="Not found\n";
    
    
        }
        in.close();
    
     //  System.out.print(results);
    
    
    
    }
    

    }