Sort by

recency

|

379 Discussions

|

  • + 0 comments

    The below code is not running into hackerrank and same code get compiled and runined successfully.

  • + 0 comments

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

    class Solutions{ public static void main(String []argh) {

        Map <String,Integer> hashMapPhoneRecord
                               = new HashMap<>();
        Scanner in = new Scanner(System.in);
        //System.out.println("Enter nth value");
        int n=in.nextInt();
        in.nextLine();
        for(int i=0;i<n;i++)
        {
            String name=in.nextLine();
            int phone=in.nextInt();
            hashMapPhoneRecord.put(name, phone);
            in.nextLine();
        }
        while(in.hasNext())
        {
            String s=in.nextLine();
            if(hashMapPhoneRecord.containsKey(s))
               System.out.println(s + "=" + hashMapPhoneRecord.get(s));
    
             else
                System.out.println("Not Found");
    
        }
        in.close();
    
    
    }
    

    }

  • + 0 comments
    //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();
            
            if (n < 0 || n > 100000) {
                throw new IllegalArgumentException("The number of people-phones cannot be lower than 0 or greater than 100,000");
            }
    		
            Map<String, Integer> phoneBook = new HashMap<>();
            
            in.nextLine();
            
    		for(int i=0; i<n; i++) {
    			String name = in.nextLine().toLowerCase();
    			Integer phone = in.nextInt();
                in.nextLine();
    			
                if (String.valueOf(phone).length() != 8) {
                    throw new IllegalArgumentException(String.format("The phone number %s is not 8 digits long", phone));
                }
                
                phoneBook.put(name, phone);
    		}
            
    		while(in.hasNext()) {
    			String s = in.nextLine().toLowerCase();
                
                Integer phone = phoneBook.get(s);
                
                if (phone == null) {
                    System.out.println("Not found");
                } else {
                    System.out.println(String.format("%s=%d", s, phone));
                }
    		}
    	}
    }
    
  • + 0 comments

    Here is Java Map solution - https://programmingoneonone.com/hackerrank-java-map-problem-solution.html

  • + 1 comment

    I don't understand the sample testcase. Tom clearly has a phone number why the output is not found??