← LinkedIn Interview Insights

LinkedIn·Machine Learning Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
Apr 2026

Summary

Did a technical screen for an ML Engineer role at LinkedIn that had a geometry/math flavor I wasn't expecting. One problem, clean setup, but the edge case handling is where things get interesting.

Questions Asked (1)

Q1

Given a line in 2D defined by the equation ax + by + c = 0 and a list of points, compute the perpendicular distance from each point to the line and return the distances in the same order as the input. Make sure to handle the degenerate case where the line is invalid.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The core formula isn't hard once you remember it: absolute value of (a*px + b*py + c) divided by sqrt(a squared plus b squared).

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and edge cases, then derive the distance formula from the line equation. Implement a function that iterates through the points, computes the distance using the formula, and handles the degenerate case where a and b are both zero. Discuss time and space complexity and potential optimizations.

Pro tip: Mention that the formula can be derived from the projection of the vector from a point on the line to the given point onto the line's normal vector. Also, explicitly handle the degenerate case by returning an empty list or raising an error, and discuss how to test it.

1. Clarify the problem and edge cases

Confirm input format, output format, and what to do when the line is invalid (a=0 and b=0). Ask if the distances should be absolute values or signed.

2. Derive the distance formula

Recall that the perpendicular distance from point (x0, y0) to line ax+by+c=0 is |a*x0 + b*y0 + c| / sqrt(a^2 + b^2). Explain why this works geometrically.

3. Handle the degenerate case

If a=0 and b=0, the line is invalid. Decide on behavior: return empty list, raise ValueError, or return None. Justify your choice.

4. Implement the solution

Write a function that iterates through the points, computes the distance for each, and collects results in order. Use a list comprehension or loop.

5. Analyze complexity and test

State time complexity O(n) and space O(n) for output. Suggest test cases: normal line, horizontal/vertical line, degenerate line, and points on the line.

Key Points to Mention

  • Distance formula: |a*x0 + b*y0 + c| / sqrt(a^2 + b^2)
  • Degenerate case: a=0 and b=0, line is invalid; handle explicitly
  • Time complexity O(n), space O(n) for output
  • Use of absolute value for distance (non-negative)
  • Potential numerical stability issues with floating-point arithmetic
  • Testing edge cases: points on line, vertical/horizontal lines, degenerate line

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