If the next character is also different in both the strings then these characters can be swapped
if ( i < n - 1 && str1 [ i + 1 ] != str2 [ i + 1 ] ) { let temp = array [ i ] ; array [ i ] = array [ i + 1 ] ; array [ i + 1 ] = temp ; cost ++ ; }