FastPrepPoker Suit Expected Profit

Poker Suit Expected Profit

IMC Trading logoIMC Trading● EasyNEW GRADPHONE SCREEN
Learn

Problem statement

For this exercise, assume a deck contains 52 ordinary cards: 13 cards in each of four suits. Add exactly one joker. Choose one suit before drawing one card uniformly from the resulting 53-card deck.

The net payoff follows these rules:

  • If the card has your chosen suit, receive winPrize.
  • The joker matches every suit, so drawing it also earns winPrize.
  • Any other card loses lossPenalty, giving net payoff -lossPenalty.

For this exercise, assume winPrize and lossPenalty are nonnegative integer inputs generalizing the reported stakes. These amounts are net gains and losses; there is no additional entry fee.

Return the expected net profit from one play as a double. Preserve a negative expectation when applicable and do not round to an integer. Complete pokerSuitExpectedProfit(winPrize, lossPenalty).

An answer is accepted when abs(actual - expected) <= 1e-9 * max(1, abs(expected)).

What the interview report shared

The report used a gain of 4 and a loss of 1, then scaled both amounts to millions. It asked about accepting one play versus repeated plays. This practice exercise calculates the per-play expectation; it does not ask for a personal choice about taking that risk.

Function

pokerSuitExpectedProfit(winPrize: int, lossPenalty: int) → double

Examples

Example 1

winPrize = 4lossPenalty = 1return = 0.32075471698113206

Under this exercise's deck model, 14 cards win and 39 lose. The expected net profit is (14 * 4 - 39 * 1) / 53 = 17 / 53, approximately 0.32075471698113206.

Example 2

winPrize = 4000000lossPenalty = 1000000return = 320754.71698113205

The reported larger stakes multiply both payoffs by 10^6. The expectation is 17000000 / 53, approximately 320754.7169811321.

Example 3

winPrize = 1lossPenalty = 1return = -0.4716981132075472

The winning and losing gains have equal magnitude, but the losing outcomes are more common. The expectation is (14 - 39) / 53 = -25 / 53, approximately -0.4716981132075472.

Constraints

  • For this exercise, assume 0 <= winPrize, lossPenalty <= 10^9.
  • The draw is uniform over all 53 cards and the chosen suit is fixed before the draw.
  • Return the unrounded expected net profit per play, which may be positive, zero, or negative.

More IMC Trading problems

See IMC Trading hiring insights
public double pokerSuitExpectedProfit(int winPrize, int lossPenalty) {
    // Write your solution here.
}
winPrize4
lossPenalty1
expected0.32075471698113206
Checking account…