Chance a Hand of Cards Multiplies to More Than a Threshold
Updated
Problem statement
There are n cards with the labels 1, 2, ..., n, one card for each label. You draw k of them without replacement, and all possible hands of k cards are equally likely.
Multiply the labels you drew. Return the chance that this product is strictly greater than threshold, as an exact fraction [numerator, denominator] in lowest terms with denominator > 0. A chance of 0 is written [0, 1] and a chance of 1 is written [1, 1].
Function
probabilityProductExceeds(n: int, k: int, threshold: int) → long[]Examples
Example 1
n = 6k = 3threshold = 30return = [2,5]There are C(6, 3) = 20 hands. Eight of them multiply to more than 30: {2, 3, 6} = 36, {2, 4, 5} = 40, {2, 4, 6} = 48, {2, 5, 6} = 60, {3, 4, 5} = 60, {3, 4, 6} = 72, {3, 5, 6} = 90 and {4, 5, 6} = 120. The hands {1, 5, 6} and {2, 3, 5} give exactly 30, which is not more than 30. So the chance is 8/20 = 2/5.
Example 2
n = 6k = 2threshold = 6return = [3,5]There are C(6, 2) = 15 pairs. Six of them multiply to 6 or less: {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6} and {2, 3} (the last two both give exactly 6). The other 9 pairs give more than 6, so the chance is 9/15 = 3/5.
Example 3
n = 5k = 5threshold = 120return = [0,1]The only possible hand holds all five cards, and 1 × 2 × 3 × 4 × 5 = 120. That equals the threshold instead of passing it, so the chance is 0, returned as [0, 1].
Constraints
1 <= k <= n <= 501 <= threshold <= 10^6- Both numbers of the answer fit in a signed 64-bit integer.
More Optiver Online Assessment questions
- Chance a Die Game Balance Reaches ZeroOA · Seen Dec 2026
- Chance a Sum of Random Draws Has a Given Number of DigitsOA · Seen Dec 2026
- Expected Draws to Remove All Green CountersOA · Seen Dec 2026
- Expected Profit of a Doubling Betting SystemOA · Seen Dec 2026
- Expected Steps Until a Random Walk Gets Far From ZeroOA · Seen Dec 2026
- Rolling Until One Face's Own Total Passes a ThresholdOA · Seen Dec 2026
- Two Ranked Teams Meeting in a Random BracketOA · Seen Dec 2026
- Overheat Prevention ControllerOA · Seen Nov 2026
- Power Cell BankOA · Seen Nov 2026
- Count Straight-Line Word Occurrences in a GridOA · Seen Sep 2026
Similar questions at other companies
- Frog Paths Without Long RunsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Maximum Score with Prime JumpsMicrosoft · OAMicrosoft interview questions
- Count Lucky TicketsThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
- Jump Game with Prime-Step RuleUber · OAUber interview questions
- Count Shipment SchedulesMorgan Stanley · OAMorgan Stanley interview questions
- Unique Paths Through a GridPeopleStrong · OAPeopleStrong interview questions
- Get Minimum OperationsJP Morgan Chase · OAJP Morgan Chase interview questions
- Jump Game with Prime-3 StepsAgoda · OAAgoda interview questions
- Find Encrypted NumberAmazon · OA
- Prime StringSnowflake · OASnowflake interview questions