Comments

It gets covered. To understand this, let's take a={1,2,3,4,8} b={9,8,7} If we had a[i]<b[i] for any case where i<min(n,m), the loop would terminate. But in the example I took, it wouldn't. Now, we are taking a number X between 1 and 9 to which both of them will be converted, hence total number of steps in 9-1. Similarly for (2,3) and (3,7). Therefore we ultimately have number X between 3 and 7 to which all of them with i<min(n,m) will be converted. Now, observe 4 and 8. 8 is already greater than X which would lie between 3 and 7. So, we don't need to take it in consideration. and for all numbers which lie between 3 and 7, we can take X less than or equal to min of them. Thus, none of them need any extra operations. Similarly, if we had extra elements in the second array, they would be smaller than b[min(m,n)-1], i,e, the element corresponding to the last element in first array. Thus, we can always take a number greater than them and they would not take any extra operations.