I am trying to sort large inputs in the fastest way in ascending order. The code is something like this:
t=gets
ti=t.to_i
r=[]
for i in(0..ti)
k=gets
r[i]=k.to_i
end
r.sort_by{|x| -x.last}
This is giving me an error saying undefined method 'last' for nil:nilclass <nomethoderror>
from tsort.rb: in sort_by
from tsort.rb in 'each'
from tsort.rb in 'sort_by'
I don't know where am I wrong.
That's what I have tried for sorting an array...which is r[]
which has all the numbers in t
! Can anyone please help.
my inputs are less than 10^6 !!