← Amazon Interview Insights

Amazon·Software Engineer·Onsite - Coding / Algorithms·Senior

SeniorPrefer not to say
Apr 2026

Summary

Amazon SWE coding round with a computational geometry problem that also doubled as an OOD design exercise. More involved than I expected, the math is manageable but the edge cases pile up fast and they clearly want class structure even on a pure algorithm question.

Questions Asked (1)

Q1

Given a list of line segments defined by their endpoints, find all pairwise intersection points and return them deduplicated.

Algorithms & Data StructuresTechnical Trade-offsSystem Design
Author's notes

The parametric approach clicked for me pretty quickly, set up the 2x2 system, compute the cross product determinant, check t1 and t2 are both in [0,1].

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints (number of segments, coordinate ranges, whether segments are closed, and expected output format). Then propose a solution that balances efficiency and simplicity, such as a sweep-line algorithm for O((n + k) log n) time, and discuss trade-offs with the naive O(n^2) approach. Finally, address deduplication of intersection points using a set with appropriate hashing or rounding.

Pro tip: Mention that floating-point precision can cause duplicate points to appear distinct; propose using exact rational arithmetic or rounding to a tolerance, and deduplicate with a hash set. This shows attention to real-world robustness.

1. Clarify requirements and constraints

Ask about input size, coordinate types (integer vs. floating-point), whether segments are closed, and if overlapping collinear segments should be handled. This ensures you solve the right problem.

2. Choose an algorithm

For small n, O(n^2) pairwise checking is acceptable. For large n, use a sweep-line algorithm (e.g., Bentley-Ottmann) to achieve O((n + k) log n) where k is the number of intersections.

3. Handle geometric computations

Implement robust segment intersection using orientation tests and parametric equations. Use exact arithmetic or epsilon comparisons to avoid precision issues.

4. Deduplicate intersection points

Store points in a hash set with a custom hash that accounts for floating-point tolerance, or round coordinates to a fixed precision before insertion.

5. Analyze complexity and trade-offs

Discuss time and space complexity of your approach, and compare with alternatives. Mention edge cases like parallel segments, shared endpoints, and collinear overlaps.

Key Points to Mention

  • Sweep-line algorithm (Bentley-Ottmann) and its O((n + k) log n) complexity
  • Naive O(n^2) approach and when it's preferable (small n, simplicity)
  • Robust orientation tests and parametric intersection formulas
  • Handling collinear overlapping segments and shared endpoints
  • Deduplication using a hash set with tolerance-based hashing
  • Floating-point precision issues and solutions (exact arithmetic, epsilon)

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