Tennis Game Winner
Updated
Problem statement
Two players, A and B, play one game of tennis. The string points lists who won each point, in order.
A player wins the game once they have at least 4 points and at least 2 more points than the other player. Return "A" or "B" if that player has won. If nobody has won yet, return the empty string "".
The string stops at the latest when the game is won: no point is played after a player has won.
Function
tennisGameWinner(points: String) → StringExamples
Example 1
points = "ABBBAB"return = "B"Tally after the six points: A has 2, B has 4. B reached 4 with a two-point margin, so the game went to B.
Example 2
points = "BAAABBBA"return = ""A takes four of the eight points and B takes the other four, so the tally is 4 to 4. A one-point or zero-point gap is not enough to close a game, so the answer is "".
Example 3
points = "BBAAABAA"return = "A"After seven points the tally is A 4, B 3, which is only a one-point gap. The eighth point goes to A, making it 5 to 3, and A takes the game.
Constraints
1 <= points.length <= 1000- Each character of
pointsis'A'or'B'. - No point comes after a player has won the game.
More Capital One Onsite Interview questions
- Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
- Sort ColorsONSITE INTERVIEW · Seen Oct 2026
- Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
- Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
- Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
- Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
- Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
- Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
- Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025
Similar questions at other companies
- Christmas Tree with N TiersVerily · ONSITE INTERVIEW
- Bounded Word Guess SolverAtlassian · ONSITE INTERVIEWAtlassian interview questions
- Document Edit EventsClickUp · ONSITE INTERVIEW
- Predict Runtime Method DispatchAMD · ONSITE INTERVIEWAMD interview questions
- Basic String Compression with Length GuardNew Relic · PHONE SCREEN · ONSITE INTERVIEW
- Print Sentences as TableAirbnb · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
- Retry with an Attempt LimitOracle · ONSITE INTERVIEWOracle interview questions
- Extract Error Log ContextFlexTrade · ONSITE INTERVIEWFlexTrade interview questions
- Run-Length Encode Consecutive Letter RunsMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions
- String Pattern ReplacementGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
Capital One interview experiences
- Capital One Coding OA Questions: 3 Experiences
- Capital One Experienced Engineer Power Day and OA: 6 Experiences
- Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
- Capital One TDP Agentic Round (AI Coding): 7 Experiences
- Capital One SWE Power Day, Level Not Reported: 6 Experiences
- Capital One TIP Intern OA and Power Day: 13 Experiences