Check if a symmetric plus is possible from the elements of the given array | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPlusPossible ( int arr [ ] , int n ) { unordered_map < int , int > mp ; for ( int i = 0 ; i < n ; i ++ ) mp [ arr [ i ] ] ++ ; bool foundModOne = false ; for ( auto x : mp ) { int element = x . first ; int frequency = x . second ; if ( frequency % 4 == 0 ) continue ; if ( frequency % 4 == 1 ) { if ( foundModOne ) return false ; foundModOne = true ; } else return false ; } } int main ( ) { int arr [ ] = { 1 , 1 , 1 , 1 , 2 , 2 , 2 , 3 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( isPlusPossible ( arr , n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }