Skip to content

Instantly share code, notes, and snippets.

@drKreso
Last active December 10, 2015 12:28
Show Gist options
  • Save drKreso/4434371 to your computer and use it in GitHub Desktop.
Save drKreso/4434371 to your computer and use it in GitHub Desktop.
def subseq(list)
list.drop(1).each_with_object([[list.first]]) do |number, sequences|
(number == sequences.last[-1] + 1) ? sequences.last << number : sequences << [number]
end.max_by(&:count).tap { |sequence| sequence.clear if sequence.count == 1 }
end
puts 'error 1' if subseq([1,0,1,2,3,0,4,5]) != [0,1,2,3]
puts 'error 2' if subseq([5,6,1,3,2,7]) != [5,6]
puts 'error 3' if subseq([2,3,3,4,5]) != [3,4,5]
puts 'error 4' if subseq([7,6,5,4]) != []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment