FastPrepTennis Game Score

Tennis Game Score

Abridge logoAbridge● MediumFULLTIMEOA

Problem statement

You are given two player names, playerOne and playerTwo, and a list winners. Each entry names the player who won the next point of one tennis game. Return the current game state after those points.

  • A player wins after scoring at least 4 points and leading by at least 2. Return the player name followed by WINS.
  • If both players have at least 3 points and their point counts are equal, return DEUCE.
  • If both players have at least 3 points and one leads by 1, return the leading player name followed by ADVANTAGE.
  • Otherwise, point counts 0, 1, 2, and 3 are displayed as 0, 15, 30, and 40.
  • For a 15-15 tie, return 15a. For a 30-30 tie, return 30a.
  • For every other ordinary score, including 0-0, return playerOne scoreOne - playerTwo scoreTwo. Keep the names in parameter order.

Practice details

For this exercise, assume the points describe one valid game and end no later than its first winning point. Both names contain only English letters, are case-sensitive, are different, and have length from 1 to 20. The winner list contains from 0 to 10000 entries, each exactly one player name.

For this exercise, assume ordinary score lines use a single ASCII space on each side of the ASCII hyphen -. Other outputs contain exactly one space between the name and WINS or ADVANTAGE.

Function

tennisScore(playerOne: String, playerTwo: String, winners: String[]) → String

Examples

Example 1

playerOne = "Alex"playerTwo = "Blair"winners = ["Alex","Blair","Alex"]return = "Alex 30 - Blair 15"

Alex wins 2 points and Blair wins 1, so their displayed scores are 30 and 15. The names stay in parameter order.

Example 2

playerOne = "Ada"playerTwo = "Ben"winners = ["Ada","Ben","Ada","Ben","Ada","Ben"]return = "DEUCE"

Both players have 3 points, so the game is at deuce.

Example 3

playerOne = "Ivy"playerTwo = "Kai"winners = ["Ivy","Ivy","Ivy","Ivy"]return = "Ivy WINS"

Ivy has 4 points and leads by 4, so Ivy wins.

Example 4

playerOne = "Mia"playerTwo = "Leo"winners = ["Mia","Leo","Mia","Leo","Mia","Leo","Mia"]return = "Mia ADVANTAGE"

The first 6 points give a 3-3 tie. Mia then leads 4-3, which is advantage.

Constraints

  • Each player name has length from 1 to 20.
  • Player names contain only English letters and are case-sensitive.
  • The two player names are different.
  • The winner list has length from 0 to 10000.
  • Every winner entry is exactly one of the two player names.
  • The list describes one valid game and contains no point after the first winning point.

More Abridge problems

See Abridge hiring insights
Saved
public String tennisScore(String playerOne, String playerTwo, String[] winners) {
    // Write your code here.
}
Checking account…