Check if a symmetric plus is possible from the elements of the given array | Function that return true if a symmetric is possible with the elements of the array ; Map to store the frequency of the array elements ; Traverse through array elements and count frequencies ; For every unique element ; Element has already been found ; The frequency of the element something other than 0 and 1 ; Driver code
function isPlusPossible ( arr , n ) { var mp = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( mp . has ( arr [ i ] ) ) mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) else mp . set ( arr [ i ] , 1 ) } var foundModOne = false ; var ans = true ; mp . forEach ( ( value , key ) => { var element = key ; var frequency = value ; if ( frequency % 4 != 0 ) { if ( frequency % 4 == 1 ) { if ( foundModOne ) ans = false foundModOne = true ; } else ans = false } } ) ; return ans ; } var arr = [ 1 , 1 , 1 , 1 , 2 , 2 , 2 , 3 , 2 ] ; var n = arr . length ; if ( isPlusPossible ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;