Basketball one on one problem

Problem Info

Basketball one on one
https://open.kattis.com/problems/basketballoneonone

My Work

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.

What I’ve Tried

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?

Question

Include a specific question if you have one.

Checklist

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

lol i’m just as confused as you are

I have no idea what you did, but I used your code and it worked just fine


Maybe you didn’t read the input and print the output?

Another way to solve the problem is to look at who scored the last point

can u please explain this solution

The solution that OP posted works by counting up the points of player a and player b, and seeing who has the higher amount.

The way I mentioned makes use of the fact that the game can only end when someone wins - it is impossible for someone to lose by scoring a point. Since the input is guaranteed to be the correct scoring history, we can say that the last person who scored won the game.

1 Like

thank you so much for the explanation and where can I find solutions for this kattis problem set ?
thnks in advance