If values at current indexes are same then increment the current score
curSum += ( a [ pos [ i ] ] [ j ] == b [ i ] [ j ] ) ; maxSum = Math . max ( maxSum , curSum ) ; } } } while ( next_permutation ( pos ) ) ;