11. Penalty Shootout Simulator

Difficulty: 

We would like to calculate which team wins in a soccer penalty shootout. Teams each have 5 kicks initially, and they will start taking kicks alternatively. A successful penalty kick has 1 point. Teams will continue until it is apparent one of them will eventually win. For example, if the score is 3-2 after each team has had 4 kicks, and the first team scores its last kick, the game immediately ends 4-2, because the last kick of the other team will not change the winner.

If after the 10 initial kicks (5 each) there is no winner, teams will have 1 extra kicks each. After extra kicks, if there is still no winner, they get 1 extra kicks each again. This continues until one of them wins.

The input to your function will be the sequence of penalty kick outcomes. An X indicates a missed kick, whereas an O shows a successful one. There is only one sequence for both teams, and they apply one at a time to the team that is taking the kick. The game may end even if there are more characters remaining in the sequence. Your function should return an array like [X, Y], where X is the final score of the first team, and Y is that of the second team.

Input:

penalty("OOXOOOOOXO");

Output:

[
  3,
  4
]

Time Limit:

500 (ms)

Hint (hover to see):

  • Hint #1



Results

ProblemsAcceptedWrongTimed OutError
180000

Input:

Expected Output:

Output: