FastPrepLight Source Hits: Sample, Compare, and Fit
Problems/Light Source Hits: Sample, Compare, and Fit

Light Source Hits: Sample, Compare, and Fit

OpenAI logoOpenAI● HardNEW GRADPHONE SCREEN
QuestionExamples

Problem statement

Source note: A research candidate graduating with a PhD described the second round of an OpenAI phone screen, a machine-learning coding question that the interviewer said also tested math reasoning. A point light source shines onto a one-dimensional line. First the candidate wrote a random sampler that, given where the source is, returns where photons land on the line. Then the interviewer supplied the theoretical density of the landing points and asked whether the sampler's curve matches it. The last two parts went the other way: from observed landing points, recover the source position, and the final part needed maximum likelihood, which the candidate reached with hints. The author said little physics background was needed. The report gives no formulas, input format, comparison method or limits.

Practice choices: photons that reach the line have an angle from straight down that is uniform between minus and plus a right angle, so a hit lands at the source's x plus its height times the tangent of that angle; the sampler is made repeatable by taking the uniform random numbers as input and mapping each to an angle by subtracting one half and multiplying by pi; the comparison returns the largest gap between the hits' empirical CDF and the theoretical CDF; the two recovery parts are merged into one fit that returns the maximum-likelihood source position and height; one function covers all three parts through a task word, and the fit ignores the position arguments; answers are judged with a relative-or-absolute tolerance of one in a million; fit inputs have at least three distinct hits and a well-conditioned maximum; and the examples and limits are ours.

The judged task matches the report at about 70%.

A point light source sits at (px, py) with py > 0, above a straight line, the x-axis, which plays the role of a one-dimensional screen. Each photon leaves the source in a random direction. Measure its direction by the angle θ from straight down: the photons that reach the line have θ spread uniformly over (-π/2, π/2), and such a photon hits the line at x = px + py · tan(θ).

The problem statement continues
Pro

Examples

Example 1

task = "SAMPLE"px = 1.0py = 2.0values = [0.5,0.75,0.25,0.9]return = [1.0,3.0,-1.0,7.15536707435]

The angles are π · (u - 1/2): 0, π/4, -π/4 and 0.4π. Their tangents are 0, 1, -1 and about 3.0776835, so the hits are 1 + 2 · tan: 1, 3, -1 and about 7.1553671, in the order of the uniform numbers.

02 · Example 2
FastPrep Pro
Reported in 1 OpenAI interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
All OpenAI interview questionsSee OpenAI hiring insights
CodePython 3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import heapq
from collections import defaultdict
 
class Solution:
def solve(self, values, queries):
# Build the adjacency structure
n = len(values)
graph = defaultdict(list)
for u, v in queries:
graph[u].append(v)
 
best = [float("inf")] * n
heap = [(0, 0)]
while heap:
cost, node = heapq.heappop(heap)
if cost > best[node]:
continue
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 OpenAI interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week