Well, I agree that the question doesn't seem to make a lot of sense.
The closest thing I can come to that's a "real" answer (i.e., not just 'set the array element to null') is this:
for(j = i; j < array.length - 1; j++) {
array[j] = array[j + 1];
}
array[array.length] = null;
Although in a worst-case analysis this is in fact O(n), it doesn't depend directly on the length of the array in the same way that copying all the elements does.
Be sure to let us know what the answer is!
|