Skip to content

Instantly share code, notes, and snippets.

@jpolvora
Created October 23, 2017 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpolvora/a626739c288e008ecfc45a9ca87c8e06 to your computer and use it in GitHub Desktop.
Save jpolvora/a626739c288e008ecfc45a9ca87c8e06 to your computer and use it in GitHub Desktop.
bool almostIncreasingSequence(int[] sequence) {
for (int i = 0; i < sequence.Length; i++) {
var items = createArray(i, sequence);
if (isIncreasingSequence(items)) return true;
}
return false;
}
int[] createArray(int indexToRemove, int[] items) {
var l = items.Length;
var newArray = new int[items.Length -1];
var it = 0;
for (int j = 0; j < l; j++) {
if (indexToRemove == j) continue;
newArray[it] = items[j];
it++;
}
return newArray;
}
bool isIncreasingSequence(int[] items) {
var maxIndex = items.Length -1;
for (int j = 0; j <= maxIndex; j++) {
var nextIndex = j + 1;
if (nextIndex > maxIndex) break;
var current = items[j];
var next = items[nextIndex];
if (next <= current) return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment