Find the most significant number and the most significant index for swapping
int index = ( max_element ( arr2 , arr2 + l2 ) - arr2 ) ; for ( int i = l1 - 1 ; i > ( l2 - 1 ) ; i -- ) { if ( arr1 [ i ] < arr2 [ index ] ) { swap ( arr1 [ i ] , arr2 [ index ] ) ; f = 1 ; break ; } } }