Created
December 8, 2017 22:17
-
-
Save arthur-mota/3640730c0b6aa0c76e1a3bca89a02d31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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