PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Applied

Find intersection of two line segments

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's skills in computational geometry and numerical robustness, focusing on line-segment intersection reasoning, endpoint touching, collinearity, and precision handling.

  • easy
  • Applied
  • Coding & Algorithms
  • Software Engineer

Find intersection of two line segments

Company: Applied

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Onsite

## Problem Given two 2D line segments **AB** and **CD**, determine whether they intersect. Each segment is defined by its endpoints: - A(x1, y1), B(x2, y2) - C(x3, y3), D(x4, y4) ### Tasks 1. Return `true/false` indicating whether the two **closed** segments intersect. 2. (Optional follow-up) If they intersect at a **single point**, return that intersection point. If they overlap over an interval (collinear overlap), return an appropriate representation (e.g., "overlap" or the overlapping segment). ### Requirements / Edge cases to handle - Vertical segments (infinite slope) and horizontal segments. - Touching at endpoints counts as intersection. - Collinear segments that overlap partially or fully. - Large coordinates (avoid floating-point precision bugs if possible). ### Example - A(0,0), B(2,2) and C(0,2), D(2,0) → intersect at (1,1) - A(0,0), B(0,2) and C(1,0), D(1,2) → do not intersect (parallel vertical) - A(0,0), B(2,0) and C(1,0), D(3,0) → collinear overlap

Quick Answer: This question evaluates a candidate's skills in computational geometry and numerical robustness, focusing on line-segment intersection reasoning, endpoint touching, collinearity, and precision handling.

Related Interview Questions

  • Merge Overlapping Collinear Segments - Applied (hard)
  • Implement a Fixed-Capacity Deque - Applied (medium)
  • Implement Nested Transactional Key-Value Store - Applied (hard)
  • Merge overlapping 2D line segments - Applied (medium)
  • Find first and last occurrence in sorted array - Applied (medium)
Applied logo
Applied
Feb 12, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
1
0

Problem

Given two 2D line segments AB and CD, determine whether they intersect.

Each segment is defined by its endpoints:

  • A(x1, y1), B(x2, y2)
  • C(x3, y3), D(x4, y4)

Tasks

  1. Return true/false indicating whether the two closed segments intersect.
  2. (Optional follow-up) If they intersect at a single point , return that intersection point. If they overlap over an interval (collinear overlap), return an appropriate representation (e.g., "overlap" or the overlapping segment).

Requirements / Edge cases to handle

  • Vertical segments (infinite slope) and horizontal segments.
  • Touching at endpoints counts as intersection.
  • Collinear segments that overlap partially or fully.
  • Large coordinates (avoid floating-point precision bugs if possible).

Example

  • A(0,0), B(2,2) and C(0,2), D(2,0) → intersect at (1,1)
  • A(0,0), B(0,2) and C(1,0), D(1,2) → do not intersect (parallel vertical)
  • A(0,0), B(2,0) and C(1,0), D(3,0) → collinear overlap

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Applied•More Software Engineer•Applied Software Engineer•Applied Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ 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.