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
function game ( v , n ) { let m = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( ! m . has ( v [ i ] ) ) m . set ( v [ i ] , 1 ) ; else m . set ( v [ i ] , m . get ( v [ i ] ) + 1 ) ; } let count = 0 ; let check = 0 ; for ( let [ key , value ] of m . entries ( ) ) { if ( value > 1 ) { if ( value >= 4 && value % 2 == 0 ) check ++ ; count ++ ; } } let flag ; if ( check % 2 != 0 ) flag = false ; if ( check % 2 != 0 ) document . write ( " " ) ; else if ( n % 2 == 0 && count % 2 == 0 ) document . write ( " " ) ; else document . write ( " " ) ; } let arr = [ 3 , 2 , 2 , 3 , 3 , 5 ] ; let size = arr . length ; game ( arr , size ) ;