FastPrepEstimate Pi from Sampled Points
Problems/Estimate Pi from Sampled Points

Estimate Pi from Sampled Points

JP Morgan Chase logoJP Morgan Chase● EasyNEW GRADONSITE INTERVIEW

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for Monte Carlo estimation of pi. The quarter-circle method, supplied-point interface, integer grid and bounds are supplied for practice. The core estimation task matches the report at about 80%.

A Monte Carlo estimate of pi can compare points inside a quarter circle with points inside its enclosing square.

For this exercise, assume the sampled points are already supplied as integer grid coordinates from 0 through 1000. Interpret (x, y) as the unit-square point (x / 1000, y / 1000). Count a point as inside the quarter circle when x² + y² <= 1000000, including its boundary.

Return 4 × insideCount / points.length as a floating-point value. Do not generate new random points. The judge checks this formula; it does not require a small sample or a finite grid to approximate pi closely.

Function

estimatePi(points: int[][]) → double

Examples

Example 1

points = [[0,0],[1000,1000],[500,500],[1000,0]]return = 3.0

Three of the four points are inside or on the quarter circle. The estimate is 4 × 3 / 4 = 3.

Example 2

points = [[1000,1000]]return = 0.0

The only point has squared distance 2000000, so no point is counted and the estimate is 0.

Example 3

points = [[600,800],[800,600],[0,1000]]return = 4.0

Every point has squared distance 1000000 and lies on the boundary. All three count, so the estimate is 4.

Constraints

  • 1 <= points.length <= 10000
  • Every point has exactly 2 coordinates.
  • 0 <= every coordinate <= 1000

More JP Morgan Chase Onsite Interview questions

  • LFU CacheONSITE INTERVIEW · Seen Nov 2026
  • LRU CacheONSITE INTERVIEW · Seen Nov 2026
  • Employees Above Average SalaryONSITE INTERVIEW · Seen Sep 2026
  • Highest-Earning Employees By DepartmentONSITE INTERVIEW · Seen Sep 2026
  • K Largest Integers in Descending OrderONSITE INTERVIEW · Seen Aug 2026
  • Tile a Three-Row Board with DominoesONSITE INTERVIEW · Seen Jan 2026
  • Two SumONSITE INTERVIEW · Seen Nov 2025
  • Intersection of Two ListsONSITE INTERVIEW · Seen Jan 2025
  • Maximum Subarray SumONSITE INTERVIEW · Seen Jan 2025
  • Fibonacci NumberONSITE INTERVIEW · Seen Nov 2024

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
  • 100 DoorsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Clock Hand Angle with Subsecond PrecisionScale AI · ONSITE INTERVIEWScale AI interview questions
  • Recover the Initial Mango PileLSEG · ONSITE INTERVIEWLSEG interview questions
  • Add Two Numeric Strings with CarryZipRecruiter · ONSITE INTERVIEWZipRecruiter interview questions
  • Three- and Five-liter Jug PlanXilinx · ONSITE INTERVIEWXilinx interview questions
  • Add Two Numbers Given as Digit ArraysCapital One · ONSITE INTERVIEWCapital One interview questions
  • Babysitter Quote with Hourly RatesUpstart · ONSITE INTERVIEWUpstart interview questions
  • Expected Value of Modified DiceJane Street · ONSITE INTERVIEWJane Street interview questions

Interview reports that mention this question

  • JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 of 3)
  • JPMorgan Quant Intern Superday: 19 Experiences (Part 1 of 3)

JP Morgan Chase interview experiences

  • JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)
  • JP Morgan Chase Data and AI Intern Superday: 11 Experiences
  • JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)
  • JPMorgan Code for Good India: 10 Experiences (Part 4 of 5)
All JP Morgan Chase interview questionsSee JP Morgan Chase hiring insights
Saved
class Solution {
    public double estimatePi(int[][] points) {
        // Write your code here.
    }
}
Checking account…