Check if a symmetric plus is possible from the elements of the given array | Java implementation of the approach ; 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
import java . util . * ; class GFG { static boolean isPlusPossible ( int arr [ ] , int n ) { HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . containsKey ( arr [ i ] ) ) { mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } else { mp . put ( arr [ i ] , 1 ) ; } } boolean foundModOne = false ; for ( Map . Entry < Integer , Integer > x : mp . entrySet ( ) ) { int element = x . getKey ( ) ; int frequency = x . getValue ( ) ; if ( frequency % 4 == 0 ) continue ; if ( frequency % 4 == 1 ) { if ( foundModOne ) return false ; foundModOne = true ; } else return false ; } return true ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 1 , 1 , 2 , 2 , 2 , 3 , 2 } ; int n = arr . length ; if ( isPlusPossible ( arr , n ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }