Skip to content

Instantly share code, notes, and snippets.

@hikilaka
Created February 24, 2017 03:17
Show Gist options
  • Save hikilaka/bb3d71642c6e6b83e1e4f0afffa6183a to your computer and use it in GitHub Desktop.
Save hikilaka/bb3d71642c6e6b83e1e4f0afffa6183a to your computer and use it in GitHub Desktop.
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