PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's ability to implement array-processing logic and apply probabilistic numerical methods, combining basic geometric reasoning with Monte Carlo estimation.

  • easy
  • Toma
  • Coding & Algorithms
  • Frontend Engineer

Approximate Pi from Random Points

Company: Toma

Role: Frontend Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

You are given an array `pts` of points sampled uniformly at random from the unit square `[0, 1] x [0, 1]`. Each point is represented as an array `[x, y]`, where `0 <= x <= 1` and `0 <= y <= 1`. A point lies inside the quarter circle of radius `1` if: `x^2 + y^2 <= 1` Implement the following function to return an approximation of the value of `pi`: ```javascript function approx(pts) { return 0; } ``` Use the fraction of points that fall inside the quarter circle to estimate `pi`. Constraints: - `pts` is never `null`. - `pts` contains at least one point. - Every point contains exactly two numeric values.

Quick Answer: This question evaluates a candidate's ability to implement array-processing logic and apply probabilistic numerical methods, combining basic geometric reasoning with Monte Carlo estimation.

Estimate pi as 4 times the fraction of sampled points inside the quarter unit circle.

Constraints

  • pts is non-empty

Examples

Input: ([[0, 0], [1, 0], [1, 1], [0.5, 0.5]],)

Expected Output: 3.0

Explanation: Three of four inside.

Input: ([[0.2, 0.2]],)

Expected Output: 4.0

Explanation: Single inside point.

Last updated: Jun 27, 2026

Related Coding Questions

  • Implement AudioStream Mixer - Toma (medium)
  • Approximate Pi from Random Points - Toma (easy)

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.