FastPrepBest Expected Result in Simplified Blackjack
Problems/Best Expected Result in Simplified Blackjack

Best Expected Result in Simplified Blackjack

Hudson River Trading logoHudson River Trading● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in two Hudson River Trading algorithm developer intern interviews. Both asked for a program that plays blackjack as well as possible, and one said the game was simplified.

The reports do not give the rules. Here the deck never runs out, you can only hit or stand, and the dealer stops at 17. A win counts 1, a tie 0 and a loss -1, with no bonus for a two-card 21. You return the best expected result, not the moves.

Our version is about 50% the same as the reported question.

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) or 2 to 10. Every new card comes from an endless deck: value 10 has probability 4/13 (ten, jack, queen or king), and each other value has probability 1/13.
  • A hand's total is the sum of its cards, except that one ace counts as 11 when that keeps the total at 21 or 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 tie 0 and a loss -1. A two-card 21 gets no extra pay, and there is no doubling, splitting or surrender.

Function

blackjackExpectedValue(card1: int, card2: int, dealerCard: int) → double

Examples

Example 1

card1 = 10card2 = 10dealerCard = 6return = 0.7039585702

Standing 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.0596907953

Standing 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.2494160210

The 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 <= 10
  • 1 <= card2 <= 10
  • 1 <= dealerCard <= 10
  • Answers within 10^-9 of 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

Interview reports that mention this question

  • Hudson River Trading interviews · 2023
  • Hudson River Trading interviews · 2025

Hudson River Trading interview experiences

  • Hudson River Trading Data Science Interviews: 2 Experiences
  • Hudson River Trading interviews · 2021
  • Hudson River Trading OA · 2021
  • Hudson River Trading interviews · 2022
All Hudson River Trading interview questionsSee Hudson River Trading hiring insights
Saved
class Solution {
    public double blackjackExpectedValue(int card1, int card2, int dealerCard) {
        // Write your code here.
    }
}
Checking account…