wrongIdx is the index of the element which is making the first array unsorted
let wrongIdx = 0 ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr1 [ i ] < arr1 [ i - 1 ] ) { wrongIdx = i ; } } let maximum = Number . MIN_VALUE ; let maxIdx = - 1 ; let res = false ;