InterviewDB
Experience
A Hand of Three Cards: Evaluate Poker-Like Hand Rankings for Three-Card Combinations
phone
Interview Experience
Problem
You are given a hand of exactly 3 cards, each as (rank, suit) where rank is 2-14 (14=Ace) and suit is one of H/D/C/S. Evaluate the hand and return its category. Categories in descending order:
STRAIGHT_FLUSH— three consecutive ranks, same suitTHREE_OF_A_KIND— all same rankSTRAIGHT— three consecutive ranks, mixed suitsFLUSH— same suit, not consecutivePAIR— exactly two same rankHIGH_CARD— none of the above
python
from typing import NamedTuple
class Card(NamedTuple):
rank: int # 2-14
suit: str # H/D/C/S
def evaluate_hand(cards: list[Card]) -> str:
...
**Input**: [(10,'H'),(11,'H'),(12,'H')] -> "STRAIGHT_FLUSH"
**Input**: [(7,'H'),(7,'D'),(7,'C')] -> "THREE_OF_A_KIND"
**Input**: [(2,'H'),(5,'D'),(3,'C')] -> "STRAIGHT"
**Input**: [(9,'H'),(3,'H'),(6,'H')] -> "FLUSH"
**Input**: [(9,'H'),(9,'D'),(2,'C')] -> "PAIR"
**Input**: [(2,'H'),(7,'D'),(K,'C')] -> "HIGH_CARD"
Follow-ups
- Ace can be low (A-2-3) or high (Q-K-A). How do you handle both cases in your straight detection?
- Given two hands of the same category, how do you compare them to determine a winner (tiebreaker logic)?
- Extend to 5-card poker hands. How does your architecture change?
- How would you generate all possible 3-card hands from a standard 52-card deck and count hands per category?
Full Details
Problem
You are given a hand of exactly 3 cards, each as (rank, suit) where rank is 2-14 (14=Ace) and suit is one of H/D/C/S. Evaluate the hand and return its category. Categories in descending order:
STRAIGHT_FLUSH— three consecutive ranks, same suitTHREE_OF_A_KIND— all same rankSTRAIGHT— three consecutive ranks, mixed suitsFLUSH— same suit, not consecutivePAIR— exactly two same rankHIGH_CARD— none of the above
python
from typing import NamedTuple
class Card(NamedTuple):
rank: int # 2-14
suit: str # H/D/C/S
def evaluate_hand(cards: list[Card]) -> str:
...
**Input**: [(10,'H'),(11,'H'),(12,'H')] -> "STRAIGHT_FLUSH"
**Input**: [(7,'H'),(7,'D'),(7,'C')] -> "THREE_OF_A_KIND"
**Input**: [(2,'H'),(5,'D'),(3,'C')] -> "STRAIGHT"
**Input**: [(9,'H'),(3,'H'),(6,'H')] -> "FLUSH"
**Input**: [(9,'H'),(9,'D'),(2,'C')] -> "PAIR"
**Input**: [(2,'H'),(7,'D'),(K,'C')] -> "HIGH_CARD"
Follow-ups
- Ace can be low (A-2-3) or high (Q-K-A). How do you handle both cases in your straight detection?
- Given two hands of the same category, how do you compare them to determine a winner (tiebreaker logic)?
- Extend to 5-card poker hands. How does your architecture change?
- How would you generate all possible 3-card hands from a standard 52-card deck and count hands per category?
Free preview. Unlock all Instacart questions →
About This Question
This is a candidate experience report from a instacart interview during the phone round.
More Instacart Interview Questions
1p3a
instacart tech phone screen experience: karat interview insights
1p3a
instacart full stack take home ai test in onsite interview process
Reddit
Interview Experience at Instacart Toronto : Seeking Clearer Feedback After a Positive Process
LeetCode
#1701 Average Waiting Time
InterviewDB
Average Travel Time: Compute Mean Trip Duration Between Station Pairs from Tap-In/Tap-Out Logs