PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Toma

Approximate Pi from Random Points

Last updated: Apr 6, 2026

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.

Related Interview Questions

  • Implement AudioStream Mixer - Toma (medium)
  • Approximate Pi from Random Points - Toma (easy)
Toma logo
Toma
Apr 1, 2026, 12:00 AM
Frontend Engineer
Technical Screen
Coding & Algorithms
1
0
Loading...

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:

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.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Toma•More Frontend Engineer•Toma Frontend Engineer•Toma Coding & Algorithms•Frontend Engineer Coding & Algorithms
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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.