PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/LinkedIn

Compute point-to-segment minimum distance

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of computational geometry and numerical robustness, testing the ability to compute Euclidean distances between a point and a line segment using analytic geometry concepts.

  • easy
  • LinkedIn
  • Coding & Algorithms
  • Machine Learning Engineer

Compute point-to-segment minimum distance

Company: LinkedIn

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

## Problem Given a 2D point **P(x, y)** and a line segment with endpoints **A(x1, y1)** and **B(x2, y2)**, compute the **minimum Euclidean distance** from point **P** to the segment **AB**. ### Input - Real numbers (or integers) representing coordinates of **P**, **A**, and **B**. ### Output - A single floating-point number: the minimum distance from **P** to segment **AB**. ### Notes / Edge cases - If the perpendicular projection of **P** onto the infinite line **AB** falls **within** the segment, the answer is the perpendicular distance. - Otherwise, the answer is `min(dist(P, A), dist(P, B))`. - Handle degenerate segments where **A == B** (distance is `dist(P, A)`). ### Constraints (assume) - Coordinates are within a reasonable range (e.g., `[-1e9, 1e9]`). - Use double precision.

Quick Answer: This question evaluates understanding of computational geometry and numerical robustness, testing the ability to compute Euclidean distances between a point and a line segment using analytic geometry concepts.

Related Interview Questions

  • Count Trips From Vehicle Logs - LinkedIn (easy)
  • Design O(1) Randomized Multiset - LinkedIn (easy)
  • Process Mutable Matrix Sum Queries - LinkedIn (medium)
  • Design a Randomized Multiset - LinkedIn (medium)
  • Can You Place N Objects? - LinkedIn (medium)
LinkedIn logo
LinkedIn
Feb 8, 2026, 12:00 AM
Machine Learning Engineer
Technical Screen
Coding & Algorithms
15
0
Loading...

Problem

Given a 2D point P(x, y) and a line segment with endpoints A(x1, y1) and B(x2, y2), compute the minimum Euclidean distance from point P to the segment AB.

Input

  • Real numbers (or integers) representing coordinates of P , A , and B .

Output

  • A single floating-point number: the minimum distance from P to segment AB .

Notes / Edge cases

  • If the perpendicular projection of P onto the infinite line AB falls within the segment, the answer is the perpendicular distance.
  • Otherwise, the answer is min(dist(P, A), dist(P, B)) .
  • Handle degenerate segments where A == B (distance is dist(P, A) ).

Constraints (assume)

  • Coordinates are within a reasonable range (e.g., [-1e9, 1e9] ).
  • Use double precision.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More LinkedIn•More Machine Learning Engineer•LinkedIn Machine Learning Engineer•LinkedIn Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.