Find the most significant index and the most significant digit to be swapped
if ( diff1 > 0 diff2 > 0 ) { if ( diff1 > diff2 ) { swap ( arr1 [ i ] , arr2 [ index2 ] ) ; break ; } else if ( diff2 > diff1 ) { swap ( arr2 [ i ] , arr1 [ index1 ] ) ; break ; } else if ( diff1 == diff2 ) { if ( index1 <= index2 ) { swap ( arr2 [ i ] , arr1 [ index1 ] ) ; break ; } else if ( index2 <= index1 ) { swap ( arr1 [ i ] , arr2 [ index2 ] ) ; break ; } } } } }