Paste Search Dynamic
Recent pastes
second_max
  1. Integer::MIN = -( 2 ** 1024)
  2.  
  3. def second_max(array)
  4.   return -1 if array.length < 2
  5.   first = Integer::MIN
  6.   second = Integer::MIN
  7.   array.each do |element|
  8.     i = element.to_i
  9.     if(i > first)
  10.       second = first
  11.             first = i
  12.     elsif (i > second && i != first)
  13.             second = i
  14.         else
  15.           next
  16.         end
  17.   end
  18.   second == Integer::MIN ? -1 : second
  19. end
  20.  
  21. puts "Outputs:"
  22. puts second_max(["123456543234556787654356787654367543", "567876543567876543567876543567876543567876543567876543", "123456323456754345643456543456654"])
  23.  
Parsed in 0.011 seconds