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.
BufferedReader is used instead of Scanner since it's faster and won't time out on HackerRank test cases when using Java8
classSolution{publicstaticvoidmain(String[]args)throwsException{/* Read input and save as entries in a HashMap */BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));intn=Integer.valueOf(br.readLine());HashMap<String,Integer>map=newHashMap<>();while(n-->0){Stringname=br.readLine();intphone=Integer.valueOf(br.readLine());map.put(name,phone);}/* Read each query and check if its in our HashMap */Strings;while((s=br.readLine())!=null){if(map.containsKey(s)){System.out.println(s+"="+map.get(s));}else{System.out.println("Not found");}}br.close();}}
Let me know if you have any questions.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Map
You are viewing a single comment's thread. Return to all comments →
Java8 solution - passes 100% of test cases
From my HackerRank solutions.
BufferedReader is used instead of Scanner since it's faster and won't time out on HackerRank test cases when using Java8
Let me know if you have any questions.