Skip to content

Instantly share code, notes, and snippets.

@arthur-mota
Created December 8, 2017 22:17
Show Gist options
  • Save arthur-mota/3640730c0b6aa0c76e1a3bca89a02d31 to your computer and use it in GitHub Desktop.
Save arthur-mota/3640730c0b6aa0c76e1a3bca89a02d31 to your computer and use it in GitHub Desktop.
def almostIncreasingSequence(sequence)
candidates = []
sequence.each_cons(2).with_index do |pair, index|
if pair.first >= pair.last
candidates << index
candidates << index + 1
end
end
if !candidates.empty?
candidates.uniq.each do |index|
dup = sequence.dup
dup.slice!(index)
return true if valid_sequence?(dup)
end
else
return true
end
return false
end
def valid_sequence?(sequence)
sequence.sort == sequence && sequence.uniq == sequence
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment