Maps to store frequencies of elements present in left and right arrays
var freq1 = new Map ( ) , freq2 = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( freq1 . has ( left [ i ] ) ) freq1 . set ( left [ i ] , freq1 . get ( left [ i ] ) + 1 ) else freq1 . set ( left [ i ] , 1 ) if ( freq2 . has ( right [ i ] ) ) freq2 . set ( right [ i ] , freq2 . get ( right [ i ] ) + 1 ) else freq2 . set ( right [ i ] , 1 ) } var ans = 0 ; for ( var i = 0 ; i < n ; i ++ ) {