Best Expected Result in Simplified Blackjack
Updated
Problem statement
Return the expected result of one hand of simplified blackjack against a dealer, when you hold two cards with values card1 and card2, the dealer's face-up card is dealerCard, and you hit or stand so that the expected result is as large as possible.
- A card value is
1(an ace) or2to10. Every new card comes from an endless deck: value10has probability4/13(ten, jack, queen or king), and each other value has probability1/13. - A hand's total is the sum of its cards, except that one ace counts as
11when that keeps the total at21or below. - On your turn you may hit (draw a card) as many times as you like, then stand. If your total goes over
21, you lose at once. - After you stand, the dealer draws a second card, then keeps drawing while the dealer's total is below
17. - If the dealer goes over
21, you win. Otherwise the higher total wins, and equal totals tie. - A win is worth
1, a tie0and a loss-1. A two-card21gets no extra pay, and there is no doubling, splitting or surrender.
Function
blackjackExpectedValue(card1: int, card2: int, dealerCard: int) → doubleExamples
Example 1
card1 = 10card2 = 10dealerCard = 6return = 0.7039585702Standing on 20 is best: against a 6 the dealer goes over 21 with chance about 0.4232, ends on 17, 18 or 19 with chance about 0.3780, ties on 20 and beats you only with 21 (about 0.0972). That gives about 0.4232 + 0.3780 - 0.0972 = 0.7040.
Example 2
card1 = 5card2 = 6dealerCard = 10return = 0.0596907953Standing on 11 wins only when the dealer goes over 21 (chance about 0.2121), which gives about -0.5758. A hit can never push 11 over 21 and still wins whenever the dealer goes over, so hitting and then playing well is better, at about 0.0597.
Example 3
card1 = 1card2 = 6dealerCard = 10return = -0.2494160210The ace counts as 11, so the total is 17, and standing gives about -0.4644. One more card cannot push this hand over 21 because the ace can drop back to 1, so hitting and then playing well gives about -0.2494.
Constraints
1 <= card1 <= 101 <= card2 <= 101 <= dealerCard <= 10- Answers within
10^-9of the correct value are accepted.
More Hudson River Trading interview questions
- Tiered Expiring Item StorePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Aligned Free-List Memory AllocatorONSITE INTERVIEW · Seen Aug 2026
- Read a File from Distributed ChunksONSITE INTERVIEW · Seen Aug 2026
- Format a Signed Integer with CommasPHONE SCREEN · Seen Nov 2026
- Order and Batch Open-Close LifecyclePHONE SCREEN · Seen Nov 2026
- Count Palindrome Addition ChoicesOA · Seen Nov 2026
- Tilting Maze BallPHONE SCREEN · Seen Oct 2026
- Count Multiples of Three with Two SevensOA · Seen Oct 2026
- Recursively Expanded Shell Command CountsOA · Seen Oct 2026
- Rotate Matrix Regions Around the DiagonalsOA · Seen Oct 2026
Similar questions at other companies
- Dice-Walk Winning ProbabilityGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Integer BreakAmazon · ONSITE INTERVIEW
- Knight Probability in ChessboardGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Count Staircases with Strictly Increasing StepseBay · ONSITE INTERVIEWeBay interview questions
- Count Divisible Power SumsGoodScore · ONSITE INTERVIEW
- Tile a Three-Row Board with DominoesJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
- Two-Egg DroppingNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
- Every Result of Grouping an ExpressionC3.ai · ONSITE INTERVIEWC3.ai interview questions
- Split a Number into Non-Decreasing GroupsExpedia · OA · ONSITE INTERVIEWExpedia interview questions
- Fibonacci NumberMicrosoft · ONSITE INTERVIEWMicrosoft interview questions