← Stripe Interview Insights

Stripe·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026Remote

Summary

Stripe coding screen for a software engineering role. One question, pretty focused on math and edge case handling. Not the most glamorous problem but it had more gotchas than I expected.

Questions Asked (1)

Q1

Implement a DISTANCE command that computes the great-circle distance in kilometers between two latitude/longitude coordinates using the Haversine formula. Validate that latitudes are in [-90, 90] and longitudes are in [-180, 180], returning ERROR for invalid inputs. Round to the nearest integer.

Algorithms & Data StructuresAPI & Integrations
Author's notes

I knew the Haversine formula existed but had never actually coded it from scratch.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the command's interface and error handling, then outline the Haversine formula step by step, emphasizing validation and rounding. Write clean, modular code with helper functions for validation and distance calculation, and test with edge cases like poles and the antimeridian.

Pro tip: Mention that you'll use the haversine formula instead of the spherical law of cosines to avoid precision issues for small distances, and explicitly handle floating-point rounding with a standard round-half-up approach.

1. Clarify requirements and interface

Confirm input format (e.g., 'DISTANCE lat1 lon1 lat2 lon2'), output format (integer km or ERROR), and any constraints like handling extra spaces or case sensitivity.

2. Validate inputs

Check that latitudes are within [-90, 90] and longitudes within [-180, 180]; if any are invalid, return ERROR immediately.

3. Implement Haversine formula

Convert degrees to radians, compute the central angle using the haversine function, then multiply by Earth's mean radius (6371 km) to get distance.

4. Round and return result

Round the computed distance to the nearest integer using standard rounding (e.g., Math.round) and return it as the output.

5. Test edge cases

Verify with known distances (e.g., same point, antipodal points, equator/prime meridian) and invalid inputs to ensure correctness.

Key Points to Mention

  • Haversine formula and why it's preferred over spherical law of cosines for numerical stability
  • Input validation ranges for latitude and longitude, and returning ERROR for invalid inputs
  • Earth's radius constant (6371 km) and its role in the formula
  • Degree-to-radian conversion and trigonometric functions (sin, cos, atan2)
  • Rounding to nearest integer and handling floating-point precision
  • Edge cases: identical points, antipodal points, poles, antimeridian, and invalid inputs

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