Find the player who wins the game of placing alternate + and | Function to check which player wins the game ; Stores the difference between + ve and - ve array elements ; Traverse the array ; Update diff ; Checks if diff is even ; Given Input ; Function call to check which player wins the game
function checkWinner ( arr , N ) { let diff = 0 ; for ( let i = 0 ; i < N ; i ++ ) { diff -= arr [ i ] ; } if ( diff % 2 == 0 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let arr = [ 1 , 2 ] ; let N = arr . length ; checkWinner ( arr , N ) ;