Basketball one on one
def who_won(records): score_a = 0 score_b = 0 for i in range(0,len(records)-1, 2): if records[i] == "A": score_a += int(records[i+1]) if records[i] == "B": score_b += int(records[i+1]) if score_a > score_b: return "A" return "B"
The code is really simple. It takes advantage of the fact that the letters are odd indexes and the corresponding scores are on the even indexes. After figuring which score is which, the scores of A and B are compared.
I’m pretty sure all we have to do is just return the letter of the winner, but I don’t think there’s really anything wrong with my code. But, alas, the solution wasn’t valid. I’m actually completely stumped right now, because I can’t think why it wouldn’t work, probably because it’s pretty late at night right now. Also, people who have experience with the kattis website, can you see where exactly you went wrong like Leetcode? Like what testcase scenario didn’t work with the code?
Include a specific question if you have one.
See How to ask for help on a problem for more information.
- Include a link to the problem
- Format your post (especially code blocks)
- Include what you’ve tried so far
- Add comments to your code
- Read the debugging module