← Meta Interview Insights

Meta·Data Scientist·Technical Phone Screen·Senior

Senior
May 2026

Summary

Meta DS interview with a surprisingly math-heavy coding round. Both parts were about vehicle collision detection, first in 1D with constant acceleration, then extended to 2D with disks and radii. Not what I expected going in as a data scientist candidate.

Questions Asked (2)

Q1

Given n vehicles moving in 1D with constant acceleration (initial position, velocity, and acceleration provided), write a function to find the earliest collision time and the pair of vehicles involved, or report that no collision occurs.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The core insight is that two vehicles i and j collide when x_i(t) = x_j(t), which reduces to a quadratic in t with coefficients from the differences in their kinematics.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model each vehicle's position as a quadratic function of time and find the earliest positive time when any two positions coincide. Use a sweep line algorithm with a priority queue of potential collision events, updating as vehicles cross. Alternatively, solve pairwise equations and take the minimum valid time.

Pro tip: Emphasize that you would first clarify assumptions (e.g., whether vehicles are points, whether collisions are elastic, and if simultaneous collisions are possible) and discuss the trade-offs between O(n^2) pairwise checking and O(n log n) sweep line approaches.

1. Clarify problem constraints

Ask about the range of n, whether accelerations can be zero or negative, and if multiple collisions at the same time need special handling. Confirm that vehicles are points and collisions occur when positions are equal.

2. Formulate pairwise collision condition

For each pair of vehicles i and j, set their position equations equal: (1/2)a_i t^2 + v_i t + x_i = (1/2)a_j t^2 + v_j t + x_j. This yields a quadratic equation in t; solve for t > 0.

3. Design efficient algorithm

For small n, compute all pairwise collision times and take the minimum. For large n, use a sweep line approach: sort vehicles by initial position, maintain a priority queue of adjacent collision events, and update when vehicles cross.

4. Handle edge cases and validate

Consider cases with no real roots, negative times, or multiple collisions at the same time. Validate with simple examples (e.g., two vehicles with constant velocities).

5. Analyze complexity and trade-offs

Discuss time and space complexity: O(n^2) for brute force, O(n log n) for sweep line. Mention that sweep line is more complex but scales better for large n.

Key Points to Mention

  • Quadratic equation for relative motion: (1/2)(a_i - a_j)t^2 + (v_i - v_j)t + (x_i - x_j) = 0
  • Discriminant determines if collision is possible; only consider t > 0
  • Sweep line algorithm with priority queue for O(n log n) time
  • Handling of simultaneous collisions and floating-point precision
  • Trade-offs between simplicity (O(n^2)) and efficiency (O(n log n))
  • Edge cases: no collision, collision at t=0, multiple vehicles colliding at same time

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Extend the collision problem to 2D: vehicles are now disks moving at constant velocity. Find the earliest time any two disks overlap (distance between centers falls at or below the sum of their radii). How do you handle vehicles that are already overlapping at t=0, and how do you manage floating-point precision?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Relative motion between two disks is also constant velocity, so the distance squared between centers is a quadratic in t.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model each pair of disks as a quadratic inequality in time and solve for the earliest t ≥ 0 where the distance between centers equals the sum of radii. Handle already-overlapping pairs by returning t=0 immediately, and use an epsilon tolerance to avoid false positives from floating-point errors.

Pro tip: Mention that you would use squared distances to avoid square roots and that you'd sort or use a priority queue if you need the earliest collision among all pairs, but for a single earliest time, a linear scan with early termination is sufficient.

1. Define the collision condition

For two disks with centers p1, p2 and radii r1, r2, collision occurs when |p1 + v1*t - (p2 + v2*t)|^2 ≤ (r1 + r2)^2. Expand to a quadratic in t: a*t^2 + b*t + c ≤ 0, where a = |v1 - v2|^2, b = 2*(p1 - p2)·(v1 - v2), c = |p1 - p2|^2 - (r1 + r2)^2.

2. Solve the quadratic inequality

Find the roots of a*t^2 + b*t + c = 0. If a ≈ 0 (relative velocities parallel or zero), handle the linear case. Otherwise, compute discriminant D = b^2 - 4ac. If D < 0, no collision; else, the earliest time is the smallest root ≥ 0, or 0 if c ≤ 0 (already overlapping).

3. Handle already-overlapping pairs

Check if c ≤ 0 at t=0 (i.e., initial distance ≤ sum of radii). If so, return t=0 immediately for that pair. This avoids unnecessary root computation and correctly identifies immediate collisions.

4. Manage floating-point precision

Use an epsilon (e.g., 1e-9) for comparisons: treat D < -epsilon as no collision, D > epsilon as two roots, and |D| ≤ epsilon as a double root. Also, when checking c ≤ 0, use c ≤ epsilon to account for rounding errors. For the earliest time, consider only roots ≥ -epsilon and clamp small negative roots to 0.

5. Iterate over all pairs and find the minimum

For each pair of disks, compute the earliest collision time (or infinity if none). Return the minimum over all pairs. If any pair yields t=0, return 0 immediately. For efficiency, consider spatial partitioning if the number of disks is large.

Key Points to Mention

  • Quadratic formulation using squared distances to avoid square roots and improve numerical stability.
  • Special cases: zero relative velocity (linear equation), no real roots (no collision), and already overlapping (t=0).
  • Floating-point tolerance (epsilon) for discriminant and distance comparisons to avoid false positives/negatives.
  • Time complexity: O(n^2) for brute-force pairwise check; mention possible optimizations like spatial hashing or sweep line for large n.
  • Handling of negative roots: only consider t ≥ 0, and clamp small negative values to 0 due to precision.
  • Edge cases: identical centers, zero radii, and extremely large velocities causing numerical overflow (use scaling if needed).

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.