FastPrepEstimate Pi from Uniform Samples
Problems/Estimate Pi from Uniform Samples

Estimate Pi from Uniform Samples

Microsoft logoMicrosoft● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Microsoft Data Scientist internship report asks candidates to estimate pi using Uniform[0,1] samples. We chose to give the two-dimensional samples as input, including points on the boundary, a fixed output precision and the limits.

You are given independent points already sampled uniformly from the unit square [0,1] x [0,1]. Each row of samples contains one point [x,y].

Estimate pi as four times the fraction of points on or inside the quarter unit circle: x*x + y*y <= 1.

Function

estimatePi(samples: double[][]) → double

Examples

Example 1

samples = [[0.0,0.0],[1.0,1.0],[0.5,0.5],[0.9,0.1]]return = 3.0

Three of four points lie in the quarter circle, so the estimate is 4 * 3 / 4 = 3.

Example 2

samples = [[1.0,0.0],[0.0,1.0],[1.0,1.0]]return = 2.6666666666666665

Boundary points are included, so two of the three points count.

Constraints

  • 1 <= samples.length <= 100000
  • samples[i].length = 2
  • 0 <= samples[i][j] <= 1
  • Results use absolute tolerance 1e-12

More Microsoft Onsite Interview questions

  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Generate an Unbiased Bit from a Biased CoinGoogle · ONSITE INTERVIEWGoogle interview questions
  • Moving Cost by Volume and CategoryWayfair · ONSITE INTERVIEWWayfair interview questions
  • Add Two Numbers Given as Digit ArraysCapital One · ONSITE INTERVIEWCapital One interview questions
  • Expected Value of Modified DiceJane Street · ONSITE INTERVIEWJane Street interview questions
  • Deterministic K-Means AssignmentsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Group-Relative Policy AdvantagesAmazon · ONSITE INTERVIEW
  • Reservoir Sampling with Recorded DrawsStackAdapt · ONSITE INTERVIEWStackAdapt interview questions
  • Sliding-Window Averages as Reduced FractionsCoinbase · ONSITE INTERVIEWCoinbase interview questions
  • Tensor-Parallel MLP GradientsOpenAI · ONSITE INTERVIEWOpenAI interview questions
  • Vectorized K-Means AssignmentsSambaNova Systems · ONSITE INTERVIEWSambaNova Systems interview questions

Interview reports that mention this question

  • Microsoft AI/ML Intern Interviews: 114 Experiences (Part 1 of 2)

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public double estimatePi(double[][] samples) {
      // Write your code here.
    }

}
Checking account…