Hacker Rank Solutions: Gem Stones

Hacker Rank Solutions: Gem Stones

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
lines = $stdin.gets.to_i

char_counts = Hash.new

lines.times do

  visted_chars =  Hash.new

  line = $stdin.gets.chomp
  line.unpack('C*').each do |char|
    if visted_chars[char].nil?
      char_counts[char] = 0 if  char_counts[char].nil?
      char_counts[char] += 1
      visted_chars[char] = true
    end
  end

end

output = []
char_counts.each { |key, value| output << key if value == lines   }

puts output.length

Comments