This is a solution for the Day 8 hackerrank.com challenge.  The basic idea of the challenge is to create a mapping of names to phone numbers based on the the given input, and later look up the phone numbers for certain names. If the entry exists, print it and its number. If it doesn't, print out Not foundHere's my solution:n = gets.strip.to_iphonebook = Hash.newn.times do       name = gets.strip    number = gets.strip     phonebook[name] = number           end  n.times do     check_name = gets.strip       if phonebook.has_key?(check_name)        print #{check_name}=#{phonebook[check_name]}        puts     else        puts Not found    endend    I was wondering about more efficient and elegant Ruby solution.  I'm not sure how big sample input was for some of those test cases, but Testcase #1,2,3 take up to 0.4s which seems a little bit too high for me.
Hackerrank challenge - Dictionaries and Maps
ruby;programming challenge;hash table
Other than the fact that you process N queries rather than continuing until EOF is reached, your solution is fine.  The main point is to understand how a Hash works in Ruby, and you've accomplished that goal well.I think that your main inefficiency is calling both print and putsprint #{check_name}=#{phonebook[check_name]}puts  instead of just puts #{check_name}=#{phonebook[check_name]}.  I/O calls can be surprisingly time-consuming.While your code is fine, I'd like to point out that Ruby can be a bit more slick and compact.There's no need to strip before calling to_i:n = gets.to_iYou can define the phonebook with a one-liner, using the Hash[ [key, value],  ] ] constructor.phonebook = Hash[(0...n).collect {[gets.strip, gets.strip]}]One way to process STDIN line by line is to use IO::each_line with a block.STDIN.each_line do |query|  query.strip!  puts phonebook.has_key?(query) ? #{query}=#{phonebook[query]} : 'Not found'end