The following code should have a run time of $O(N)$,
int min = INTEGER.MAX_VALUE;
int max = INTEGER.MIN_VALUE;
for (int x : array) {
if (x < min) min = x;
if (x > min) max = x;
}
but what about the following code?
int min = INTEGER.MAX_VALUE;
int max = INTEGER.MIN_VALUE;
for (int x : array) {
if (x < min) min = x;
}
for (int x : array) {
if (x > min) max = x;
}