I learned a peaked guide, and it really helped me pick up the language pretty quickly. After that, I started solving some coding puzzles using Ruby. It just helps many get used to the language that I feel.
I'm stuck with one such mystery. I solved it very easily, as it is pretty straight forward, but the decision is rejected (by the host site) with the error "Time Exceded"! I know that Ruby cannot compete with C / C ++ speed, but should it be able to answer a tiny puzzle on a website that makes decisions in Ruby?
the puzzle is just a normal view.
This is my decision
array ||= []
gets.to_i.times do
array << gets
end
puts array.sort
My question is: is there any other way to achieve high-speed sorting with Ruby? I use the basic one Array#sorthere, but is there a way to do this faster, although that means it has more lines of code?
source
share