Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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