Make a list's elements consecutive by an integer n
remove() is most likely linear. If so, the entire method has a quadratic time complexity. However there is a linear algorithm, which does not rely on remove():

    int kept = 0;
    int unknown = 1;
    while (unknown &lt; size) {
        if (Math.abs(data[kept] - data[unknown]) == n) {
            data[++kept] = data[unknown];
        }
        unknown++;
    }
    erase(kept + 1, size);  // or whatever method you have to delete the tail of the array
    return unknown - kept &gt; 1;


A perk benefit of this approach is that you don't need to reassign isChanged every time an element is removed.