Game of replacing array elements | C # program for Game of Replacement ; Function return which player win the game ; Create hash that will stores all distinct element ; Traverse an array element ; Driver code
using System ; using System . Collections . Generic ; public class GameOfReplacingArrayElements { public static int playGame ( int [ ] arr ) { HashSet < int > set = new HashSet < int > ( ) ; foreach ( int i in arr ) set . Add ( i ) ; return ( set . Count % 2 == 0 ) ? 1 : 2 ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 1 , 2 , 2 , 2 , 2 } ; Console . Write ( " Player ▁ " + playGame ( arr ) + " ▁ wins " ) ; } }