← Uber Interview Insights

Uber·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
Apr 2026

Summary

Uber ML Engineer interview with a geometry coding problem. Nothing too wild but the math details matter more than you'd expect.

Questions Asked (1)

Q1

Given four 2D points, write a function to determine whether they form a valid square.

Algorithms & Data Structures
Author's notes

My first instinct was to sort the points and check side lengths, which works for axis-aligned cases but falls apart once the square is rotated.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First clarify the definition of a square (four equal sides, four right angles, non-degenerate). Then propose an efficient algorithm: compute all six pairwise squared distances, sort them, and check that the four smallest are equal and positive, and the two largest are equal and exactly twice the smallest. This avoids floating-point issues and handles any point order.

Pro tip: Mention that using squared distances avoids floating-point precision problems, and explicitly handle duplicate points (zero distances) to reject degenerate cases. Also, note that this method works for any input order and runs in O(1) time.

1. Clarify requirements and edge cases

Confirm that the four points must be distinct and form a non-degenerate square. Ask whether the points are given as integers or floats, and whether the square can be rotated.

2. Choose a robust algorithm

Decide to compute all pairwise squared distances (6 total) and use the property that a square has four equal sides and two equal diagonals that are twice the side length squared.

3. Implement the check

Compute the six squared distances, sort them, and verify that the first four are equal and positive, and the last two are equal and exactly twice the first value.

4. Analyze complexity and test

State that the algorithm runs in O(1) time and space. Walk through test cases: a valid square, a rectangle, a rhombus, and points with duplicates.

Key Points to Mention

  • Use squared distances to avoid floating-point precision issues.
  • A square has four equal sides and two equal diagonals that are √2 times the side length.
  • Sorting the six distances simplifies the check: four smallest equal and positive, two largest equal and twice the smallest.
  • Handle duplicate points (zero distances) to reject degenerate cases.
  • The algorithm works regardless of the order of the input points.
  • Time and space complexity are O(1) since the number of points is fixed.

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