Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Dice Scoring Probability

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Dice Scoring Probability. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

A Goldman Sachs Marquee simulation needs to estimate the probability that a roll of several ordinary dice produces a specified number of twos. Define a roll's score as the number of dice showing face 2.

Implement probability_of_twos(num_dice, target_twos) to return the probability that exactly target_twos of num_dice independent six-sided dice show 2.

Formal Specification

  • Input: two integers, num_dice >= 0 and 0 <= target_twos <= num_dice.
  • Output: a floating-point probability between 0.0 and 1.0.
  • Every die is fair, with faces 1 through 6.

Constraints

  • 0 <= num_dice <= 1000
  • 0 <= target_twos <= num_dice
  • Each die is fair and has six faces
  • Do not enumerate all 6 ** num_dice outcomes

Function Signature

def probability_of_twos(num_dice, target_twos):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output