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.
this is a really good solution, it inspired me to create one on the same idea but without classes
#!/bin/ruby
require 'json'
require 'stringio'
n = gets.to_i
dic = {}
n.times do |n_itr|
opContact = gets.rstrip.split
op = opContact[0].to_s.rstrip
contact = opContact[1].to_s.rstrip
if op == "add"
word = ""
contact.split("").each do |letter|
word += letter
if (dic[word])
dic[word] += 1
else
dic[word] = 1
end
end
elsif op == "find"
puts dic[contact] || 0
end
end
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tries: Contacts
You are viewing a single comment's thread. Return to all comments →
this is a really good solution, it inspired me to create one on the same idea but without classes
#!/bin/ruby