← Stripe Interview Insights

Stripe·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Stripe coding screen for a software engineer role. One problem, geospatial math, which sounds like a niche curveball but is really just implementation plus input validation. Not the worst way to spend 45 minutes.

Questions Asked (1)

Q1

Implement a DISTANCE command that computes the great-circle distance in kilometers between two lat/lon coordinate pairs using the Haversine formula, with input validation that returns ERROR for out-of-range coordinates.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I knew the Haversine formula existed but definitely could not have recited it cold.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the function signature and validation rules, then implement the Haversine formula step by step, converting degrees to radians and using the Earth's mean radius. Test with known distances and edge cases like antipodal points and invalid inputs.

Pro tip: Mention that you'll use the haversine formula's numerically stable form (using atan2) to avoid precision issues for small distances, and discuss the trade-off between using a spherical Earth model versus a more accurate ellipsoidal model like Vincenty's.

1. Clarify requirements and edge cases

Confirm the expected input format (e.g., two lat/lon pairs), output (distance in km), and error handling (return ERROR for out-of-range coordinates). Ask about precision requirements and whether to use a spherical or ellipsoidal Earth model.

2. Validate inputs

Check that latitudes are between -90 and 90 and longitudes between -180 and 180. If any coordinate is out of range, return ERROR immediately.

3. Convert degrees to radians

Convert all latitude and longitude values from degrees to radians, as trigonometric functions in most languages expect radians.

4. Apply Haversine formula

Compute the differences in latitude and longitude, then calculate a = sin²(Δφ/2) + cos φ1 * cos φ2 * sin²(Δλ/2). Use c = 2 * atan2(√a, √(1−a)) for numerical stability, and distance = R * c, where R is Earth's radius (mean radius 6371 km).

5. Test and discuss trade-offs

Test with known distances (e.g., between two cities) and edge cases (same point, antipodal points). Discuss the trade-off between simplicity (Haversine) and accuracy (Vincenty), and mention potential floating-point precision issues.

Key Points to Mention

  • Haversine formula and its derivation from the spherical law of cosines
  • Input validation: latitude [-90, 90], longitude [-180, 180]
  • Degree to radian conversion
  • Use of atan2 for numerical stability
  • Earth's radius: mean radius 6371 km (or 6371.0088 km)
  • Trade-offs: spherical vs. ellipsoidal models, performance vs. accuracy

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