Texas Hold'em Winners
Updated
Problem statement
In Texas Hold'em, five shared cards lie face up on the table, called the board. Each player also holds two private cards, given in hands. A player's hand is the best five-card hand they can make from their seven cards: the five board cards plus their own two.
Each card is a string of two characters: its rank, then its suit. The ranks from low to high are 2 to 9, T (ten), J, Q, K and A. The suits are C, D, H and S.
Five-card hands rank from strongest to weakest:
- Straight flush: five cards of the same suit with ranks in a row.
- Four of a kind: four cards of one rank.
- Full house: three cards of one rank and two of another.
- Flush: five cards of the same suit.
- Straight: five cards with ranks in a row.
- Three of a kind: three cards of one rank.
- Two pair: two cards of one rank and two of another.
- One pair: two cards of one rank.
- High card: none of the above.
An ace can be the top of a straight (T J Q K A) or the bottom (A 2 3 4 5). A 2 3 4 5 is the lowest straight, with 5 as its top card. A straight cannot wrap around, so Q K A 2 3 is not a straight.
Two hands of the same kind are compared by rank only. Suits never break a tie.
- Straight flush or straight: the higher top card wins.
- Four of a kind, full house, three of a kind, two pair or one pair: first compare the ranks of the groups, the bigger group first and, for two pair, the higher pair first. Then compare the other cards from highest to lowest.
- Flush or high card: compare the five cards from highest to lowest.
If everything is equal, the hands tie.
Return the indexes of all players with the best hand, in increasing order. More than one player wins when they tie.
Function
findWinners(board: String[], hands: String[][]) → int[]Examples
Example 1
board = ["KS","7D","7C","2H","9S"]hands = [["KH","3D"],["AH","AS"],["7S","QC"]]return = [2]Player 0 can make two pair, kings and sevens, with a nine: KS KH 7D 7C 9S.
Player 1 can make two pair, aces and sevens, with a king: AH AS 7D 7C KS. This beats player 0 because aces are higher than kings.
Player 2 has a third seven, so they can make three of a kind: 7D 7C 7S KS QC. Three of a kind beats two pair, so only player 2 wins.
Example 2
board = ["5S","6D","7H","8C","9S"]hands = [["2D","2H"],["KC","QD"],["4H","3C"]]return = [0,1,2]The board is already a straight from 5 to 9, so every player has at least that straight.
Player 0's pair of twos and player 1's king and queen do not help. Player 2 can make 3 4 5 6 7 and 4 5 6 7 8, but both are lower than the board's straight, which tops out at 9.
All three players have the same best hand, so they tie and the answer is [0,1,2].
Example 3
board = ["AH","2D","3H","4C","9H"]hands = [["5S","KD"],["KH","7H"],["5H","6H"]]return = [1]Player 0 can make the lowest straight, A 2 3 4 5, where the ace counts as low.
Player 1 has five hearts: AH KH 9H 7H 3H. That is a flush, which beats a straight.
Player 2 also has five hearts: AH 9H 6H 5H 3H. That is a flush too. They can also make the straight 2 3 4 5 6, but the flush is better. It is not a straight flush, because 2D and 4C are not hearts.
Both flushes start with an ace. The second-highest cards are a king for player 1 and a nine for player 2, so player 1 wins.
Constraints
board.length == 52 <= hands.length <= 10hands[i].length == 2- Every card has length
2: a rank from"23456789TJQKA"followed by a suit from"CDHS". - All cards in
boardandhandsare different.
More Airbnb Phone Screen questions
- Read Across Sound TracksPHONE SCREEN · Seen Nov 2026
- Text JustificationPHONE SCREEN · Seen Nov 2026
- Decode and Store StringsPHONE SCREEN · Seen Oct 2026
- Print Sentences as TablePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Detonate Bombs with Chain ReactionsPHONE SCREEN · Seen Aug 2026
- Smallest Common RegionPHONE SCREEN · Seen Aug 2026
- Longest Chain BookingPHONE SCREEN · Seen Aug 2026
- Nested List Iterator with RemovePHONE SCREEN · Seen Jul 2026
- Parse Query StringPHONE SCREEN · Seen May 2026
- Pacific Atlantic Water FlowPHONE SCREEN · Seen May 2023
Similar questions at other companies
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Merchant Payout Scheduler, Part 2: Per-Merchant SchedulesStripe · PHONE SCREENStripe interview questions
- Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
- Camel CardsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Message Event AggregationOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Shopping Cart ReceiptSony Interactive Entertainment PlayStation · PHONE SCREEN
- Banking System with Pending Transfer AcceptanceCircle · PHONE SCREENCircle interview questions
- Server Log Summary and Minute AnomaliesNinjaTrader · PHONE SCREEN
- Streaming Top-K Frequent ElementsNVIDIA · PHONE SCREENNVIDIA interview questions
- Interview Slot BookingTrueFoundry · PHONE SCREEN
Interview reports that mention this question
Airbnb interview experiences
- Airbnb SWE OA: Four-Level Banking System: 1 Experience
- Airbnb Campus and Full-Time SWE OA / Interviews: 9 Experiences
- Airbnb Intern OA and Phone Screens: 17 Experiences (Part 6 of 7)
- Airbnb Intern OA and Onsite Rounds: 16 Experiences (Part 5 of 7)
- Airbnb Intern OA, Diplomacy Game: 19 Experiences (Part 4 of 7)