Approximate Pi Using Monte Carlo (Quarter Circle)

Asked at Veeva Systems · Coding Questions · Difficulty: Easy

You are given an array of random points `pts` in the unit square, where each point is `[x, y]` with `0 <= x <= 1` and `0 <= y <= 1`.\n\nA point is inside the quarter disk of radius 1 (first quadrant) if `x^2 + y^2 <= 1`; otherwise it is outside.\n\nImplement `approx(pts)` to return an approximation of `pi` using the points in `pts`.\n\n## Requirements\n- `pts` is not null and contains at least one point.\n- Return a number (floating-point) as the approximation of `pi`.\n\n## Signature\nThe prompt shows a JavaScript signature `function approx(pts) { }`; the executable version here uses the…

Loading the problem…