Two player game in which a player can remove all occurrences of a number | C # implementation for Two player game in which a player can remove all occurrences of a number ; Function that print whether player1 can wins or loses ; Storing the number of occurrence of elements in unordered map ; Variable to check if the occurrence of repeated elements is >= 4 and multiple of 2 or not ; Count elements which occur more than once ; Driver code
using System ; using System . Collections . Generic ; class GFG { public static void game ( int [ ] v , int n ) { Dictionary < int , int > m = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! m . ContainsKey ( v [ i ] ) ) m . Add ( v [ i ] , 1 ) ; else m [ v [ i ] ] = m [ v [ i ] ] + 1 ; } int count = 0 ; int check = 0 ; foreach ( KeyValuePair < int , int > i in m ) { if ( i . Value > 1 ) { if ( i . Value >= 4 && i . Value % 2 == 0 ) check ++ ; count ++ ; } } bool flag ; if ( check % 2 != 0 ) flag = false ; if ( check % 2 != 0 ) Console . WriteLine ( " Yes " ) ; else if ( n % 2 == 0 && count % 2 == 0 ) Console . WriteLine ( " No " ) ; else Console . WriteLine ( " Yes " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 2 , 2 , 3 , 3 , 5 } ; int size = arr . Length ; game ( arr , size ) ; } }