Space Saving algorithm implementation in Ruby