Find the winner of a game where scores are given as a binary string | function for winner prediction ; increase count ; check losing condition ; check winning condition ; check tie on n - 1 point ; increase count ; check for 2 point lead ; condition of lost ; condition of win ; Driver Code
def predictWinner ( score , n ) : NEW_LINE INDENT count = [ 0 for i in range ( 2 ) ] NEW_LINE for i in range ( 0 , len ( score ) , 1 ) : NEW_LINE INDENT index = ord ( score [ i ] ) - ord ( '0' ) NEW_LINE count [ index ] += 1 NEW_LINE if ( count [ 0 ] == n and count [ 1 ] < n - 1 ) : NEW_LINE INDENT print ( " GEEKS ▁ lost " , end = " ▁ " ) NEW_LINE return NEW_LINE DEDENT if ( count [ 1 ] == n and count [ 0 ] < n - 1 ) : NEW_LINE INDENT print ( " GEEKS ▁ won " , end = " ▁ " ) NEW_LINE return NEW_LINE DEDENT if ( count [ 0 ] == n - 1 and count [ 1 ] == n - 1 ) : NEW_LINE INDENT count [ 0 ] = 0 NEW_LINE count [ 1 ] = 0 NEW_LINE break NEW_LINE DEDENT DEDENT i += 1 NEW_LINE for i in range ( i , len ( score ) , 1 ) : NEW_LINE INDENT index = ord ( score [ i ] ) - ord ( '0' ) NEW_LINE count [ index ] += 1 NEW_LINE if ( abs ( count [ 0 ] - count [ 1 ] ) == 2 ) : NEW_LINE INDENT if ( count [ 0 ] > count [ 1 ] ) : NEW_LINE INDENT print ( " GEEKS ▁ lost " , end = " ▁ " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " GEEKS ▁ won " , end = " ▁ " ) ; NEW_LINE DEDENT return NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT score = "1001010101111011101111" NEW_LINE n = 15 NEW_LINE predictWinner ( score , n ) NEW_LINE DEDENT