If elements of any pair are not equal and their frequency is not same update the isArrayPossible variable to false and break through the loop
if ( i . first != s1 - i . first ) { if ( mp [ i . first ] != mp [ s1 - i . first ] ) { isArrayPossible = false ; break ; } }