Which of the following "for" loops can be used instead of the inner for loop so that the output doesn't change?
for(j = 1; j < arr[idx] + len; j++)
for(j = 0; j < arr[idx] - len; j++)
for(j = idx + 1; (j < len && j <= arr[idx] + idx); j++)
No change is required
Answer and explanation
None of the above mentioned "for" loops can be used instead of the inner for loop. Note, for(j = idx + 1; (j < len && j <= arr[idx] + idx); j++) covers the same range as the inner for loop but it produces the wrong output because the indexing inside the loops changes as "j" takes different values in the two "for" loops.
