Given a binary string representing the scores of a Volleyball match. The task is to find the winner of the match according to below conditions:
- In volleyball, the two teams play with each other and the team which scores 15 points first will be the winner except the case when both teams have reached to 14 points.
- In the case when both teams have reached 14 points then the team maintaining a lead of two points will be the winner.
In the given binary string, 0 means GEEK’s team lose a point and 1 means GEEK’s team win a point. You have to find whether GEEK’s team had won or lost the match.
Input : score = 01011111111110110101 Output : GEEK's won Input : score = 010101010101010101010101010100 Output : GEEK's lost
Case I : When one of the team scores 15 points first and the second team has scored less than 15 points. Then traverse the given binary string and store the count of zero’s and one’s. After that if you get the count of one to be 15 and the count of zero less than 15 then GEEK’s won and on the other hand if you get count of zero to be 15 and count of one less than 15 then GEEK’s lost.
Case II : When both of the team scores 14 points then reset count of both to zero and for each zero or one increment their count and simultaneously check if abs(count – count) is equal to 2, if this happens then it means any one of the team had scored two more points than its opponent and will be the winner. You can than find the winner on the value of count and count.
Below is the implementation of the above approach:
This article is contributed by Shivam Pradhan (anuj_charm). If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Find the winner of the game
- Dictionary and counter in Python to find winner of election
- Find winner of an election where votes are represented as candidate names
- Find the maximum possible Binary Number from given string
- Find the n-th binary string in sorted order
- Find the last remaining Character in the Binary String according to the given conditions
- Find i'th Index character in a binary string obtained after n iterations
- Find if it is possible to make a binary string which contanins given number of "0", "1" , "01" and "10" as sub sequences
- Periodic Binary String With Minimum Period and a Given Binary String as Subsequence.
- String obtained by reversing and complementing a Binary string K times
- Find the occurrence of the given binary pattern in the binary representation of the array elements
- Longest sub string of 0's in a binary string which is repeated K times
- Print string after removing all (“10” or “01”) from the binary string
- Largest sub-string of a binary string divisible by 2
- Python | Check if a given string is binary string or not
- Find the longest sub-string which is prefix, suffix and also present inside the string
- Find the longest sub-string which is prefix, suffix and also present inside the string | Set 2
- String Range Queries to find the number of subsets equal to a given String
- Find the count of palindromic sub-string of a string in its sorted form
- Find length of longest subsequence of one string which is substring of another string