Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Random Points in a Circle and Pi
00:00
5 left

Random Points in a Circle and Pi

MediumPython

Problem

How would you generate random points in a circle and use them to estimate pi, given a center and radius?

Implement estimate_pi(center_x, center_y, radius, samples, seed). Generate points uniformly in the circle's bounding square, count points inside the circle, and return 4 * inside / samples. Use seed for deterministic results and include boundary points as inside.

Inputs are numeric center coordinates and radius, a positive sample count, and an integer seed. Return a floating-point estimate.

Constraints

  • -10^9 <= center_x, center_y <= 10^9
  • 0 <= radius <= 10^9
  • 1 <= samples <= 1000
  • seed is an integer
  • Return a floating-point value
  • Points on the boundary count as inside

Function Signature

def estimate_pi(center_x, center_y, radius, samples, seed):
Interviewer

Your question is Random Points in a Circle and Pi. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.