Skip to main content

Posts

Showing posts with the label hackerrank practice

java hashset hackerrank solution - java 15

 java hashset hackerrank solution - java 15 for explanation watch video: code: import  java.io.*; import  java.util.*; public   class  Solution {      public   static   void  main(String[] args) {         Scanner scn =  new  Scanner(System.in);          int  t = scn.nextInt();         scn.nextLine();         HashSet<String> hs =  new  HashSet<>();          for ( int  i= 0 ;i<t;i++){             String s = scn.nextLine();             hs.add(s);             System.out.println(hs.size());         }     } }

java map hackerrank solution - Java 15

   java map hackerrank solution - Java 15 for explanation watch video : Code: import  java.io.*; import  java.util.*; public   class  Solution {      public   static   void  main(String[] args) {         Scanner scn =  new  Scanner(System.in);          int  n = scn.nextInt();         scn.nextLine();         HashMap<String,Integer> hm =  new  HashMap<>();          for ( int  i= 0 ;i<n;i++){             String name = scn.nextLine();              int  mobile = scn.nextInt();             scn.nextLine();             hm.put(name,mobile);         }          while (scn.hasNext()){             String name = scn.nextLine();              if (hm.containsKey(name)){                 System.out.println(name+ "=" +hm.get(name));             } else {                 System.out.println( "Not found" );             }         }        } }