Random Chord Length on a Circle
Updated
Problem statement
Two points are chosen on the edge of a circle of radius r. Each point is uniformly random on the edge, and the two choices are independent. Let d be the straight-line distance between them, which is the length of the chord joining them.
Return the expected value of d^k, that is, the average of the distance raised to the power k.
Your answer is accepted if its absolute error or its relative error is at most 10^-9.
Function
expectedChordPower(r: int, k: int) → doubleExamples
Example 1
r = 1k = 1return = 1.2732395447351628This is the interview question. Turn the circle so the first point is fixed. The angle θ between the two points, measured at the center, is then uniform from 0 to 2π.
The two radii and the chord form an isosceles triangle, so the chord is d = 2 sin(θ/2) when r = 1. Its average is (1 / 2π) × ∫ 2 sin(θ/2) dθ over 0 to 2π, which is (1 / 2π) × 8 = 4/π, about 1.2732.
Example 2
r = 1k = 2return = 2.0Now d^2 = 4 sin²(θ/2) = 2 - 2 cos θ. The average of cos θ over a full turn is 0, so the answer is exactly 2.
With example 1, the variance of the distance is 2 - (4/π)^2 = 2 - 16/π^2, about 0.3789.
Example 3
r = 3k = 3return = 91.67324722093171Write u = θ/2, which is uniform from 0 to π. Then d = 6 sin u, so d^3 = 216 sin³ u.
The average of sin³ u over that range is 4/(3π), so the answer is 216 × 4/(3π) = 288/π, about 91.673.
Constraints
1 <= r <= 10001 <= k <= 50
More Susquehanna International Group (SIG) Phone Screen questions
- Dice Sum That Is a Multiple of mPHONE SCREEN · Seen Nov 2026
- Find Median from Data StreamPHONE SCREEN · Seen Nov 2026
- Painting Arcs to Nearest Neighbors on a CirclePHONE SCREEN · Seen Sep 2026
- Filter Movies by Inclusive Year RangePHONE SCREEN · Seen Jul 2026
- Best Single Reroll for Five DicePHONE SCREEN · Seen Feb 2026
- Catching the Bus to the MoviePHONE SCREEN · Seen Jan 2026
- Two Dice Summing to a TargetPHONE SCREEN · Seen Jan 2026
- Median of Uniform Draws in an IntervalPHONE SCREEN · Seen Oct 2025
- One Number Is the Average of the Other TwoPHONE SCREEN · Seen Jun 2025
- Which Coin Pattern Shows Up FirstPHONE SCREEN · Seen May 2025
Similar questions at other companies
- Integers With Multiple Sum of Two CubesCharta Health · PHONE SCREEN · ONSITE INTERVIEWCharta Health interview questions
- Dice-Walk Winning ProbabilityGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Logistic Regression with Gradient DescentYahoo · PHONE SCREENYahoo interview questions
- Evaluate an Arithmetic Expression Written in WordsBrex · PHONE SCREEN
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Integer to English Words in USD and INR StylesVeeam · PHONE SCREEN
- Adaptive Calibration ErrorOpenAI · PHONE SCREENOpenAI interview questions
- Sum of Smallest Non-DivisorsThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
- Square Root FunctionCitadel · PHONE SCREENCitadel interview questions
- Reorderable Task Scheduler With CooldownWaymo · PHONE SCREENWaymo interview questions