Created
February 24, 2017 03:17
-
-
Save hikilaka/bb3d71642c6e6b83e1e4f0afffa6183a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
bool almostIncreasingSequence(std::vector<int> sequence) { | |
auto begin = std::begin(sequence); | |
auto end = std::end(sequence); | |
if (sequence.size() < 2) { | |
// outside constrains | |
return false; | |
} | |
bool has_skipped = false; | |
int last_value = *begin; | |
for (auto itr = std::next(begin); itr != end; ++itr) { | |
if (last_value >= *itr) { | |
if (has_skipped) { | |
// already skipped 1 number already | |
return false; | |
} | |
has_skipped = true; | |
} | |
last_value = *itr; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment