Find the player who rearranges the characters to get a palindrome string first | Function that returns the winner of the game ; Initialize the freq array to 0 int freq [ 26 ] ; memset ( freq , 0 , sizeof freq ) ; $freg = array_fill ( ) ; Iterate and count the frequencies of each character in the string ; Count the odd occurring character ; If odd occurrence ; Check condition for Player - 1 winning the game ; Driver code ; Function call that returns the winner
< ? php function returnWinner ( $ s , $ l ) { $ freq = array_fill ( 0 , 26 , 0 ) ; for ( $ i = 0 ; $ i < $ l ; $ i ++ ) { $ freq [ $ s [ $ i ] - ' a ' ] ++ ; } $ cnt = 0 ; for ( $ i = 0 ; $ i < 26 ; $ i ++ ) { if ( $ freq [ $ i ] & 1 ) $ cnt ++ ; } if ( $ cnt == 0 $ cnt & 1 ) return 1 ; else return 2 ; } $ s = " abaaab " ; $ l = strlen ( $ s ) ; $ winner = returnWinner ( $ s , $ l ) ; echo " Player - " , $ winner ; ? >