Input: N = 7, X[] = {1, 0, 1, 1, 1, 0, 0}
Output: A
Explanation: The moves of the games by both players are as follows:
- Player B: Selects A[ 7 ] = 0. Now update A[ 7 ] = 1.
- Player A: Selects A[ 6 ] = 0. Now update A[ 6 ] = 1.
Now, player B can''t make any move because there is no adjacent index, such that the element at that index is equal to 0.
Input: N = 8, X[] = {1, 1, 0, 0, 0, 0, 0, 1}
Output: B
Explanation: The moves of the game are as follows:
- Player B: Selects A[5]=0. Now update A[5]=1.
- Player A: Selects A[4]=0. Now update A[4]=1.
- Player B: Selects A[6]=0. Now update A[6]=1.
- Player A: Selects A[3]=0. Now update A[3]=1.
- Player B: Selects A[7]=0. Now update A[7]=1.
Now, player A can't make any move because there is no adjacent index, such that the element at that index is equal to 0.
Iterate through the array a[] and calculate the maximum frequency of consecutive zeros seen so far and store in variable maxc1 and calculate the second maximum frequency of consecutive zeros seen so far and store in variable maxc2. Now check if the maximum frequency maxc1 is odd and the second maximum frequency maxc2 is strictly less than (maxc1+1)/2, player "B" wins, else player "A" wins.