PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Applied

Merge collinear overlapping 2D segments

Last updated: Mar 29, 2026

Quick Overview

This question evaluates computational geometry skills, numerical robustness, and algorithmic implementation for merging collinear, overlapping 2D segments in the Coding & Algorithms domain.

  • medium
  • Applied
  • Coding & Algorithms
  • Software Engineer

Merge collinear overlapping 2D segments

Company: Applied

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given a collection of 2D line segments. Each segment may be represented either as: - two endpoints `(x1, y1)` and `(x2, y2)`, or - a polyline with multiple points, where **all points are guaranteed to be collinear** (so the polyline still lies on a single infinite line). Two segments are mergeable if: 1. They lie on the **same infinite line** (collinear), and 2. Their projections on that line **overlap or touch** (i.e., they intersect or share an endpoint). ## Task Merge all mergeable segments and output the resulting set of **maximal** segments (no two output segments should be further mergeable). ## Notes / edge cases - Handle **vertical lines** correctly (slope is infinite). - Avoid floating-point precision issues when grouping by line if possible. - Segments may be given with endpoints in any order. ## Input/Output - Input: list of segments/polylines with integer coordinates. - Output: list of merged segments, each as two endpoints `(xa, ya)` and `(xb, yb)`. ## Constraints - Up to ~10^5 segments. - Coordinates fit in 32-bit signed integers.

Quick Answer: This question evaluates computational geometry skills, numerical robustness, and algorithmic implementation for merging collinear, overlapping 2D segments in the Coding & Algorithms domain.

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 intersection of two line segments - Applied (easy)
Applied logo
Applied
Jan 22, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
1
0
Loading...

You are given a collection of 2D line segments. Each segment may be represented either as:

  • two endpoints (x1, y1) and (x2, y2) , or
  • a polyline with multiple points, where all points are guaranteed to be collinear (so the polyline still lies on a single infinite line).

Two segments are mergeable if:

  1. They lie on the same infinite line (collinear), and
  2. Their projections on that line overlap or touch (i.e., they intersect or share an endpoint).

Task

Merge all mergeable segments and output the resulting set of maximal segments (no two output segments should be further mergeable).

Notes / edge cases

  • Handle vertical lines correctly (slope is infinite).
  • Avoid floating-point precision issues when grouping by line if possible.
  • Segments may be given with endpoints in any order.

Input/Output

  • Input: list of segments/polylines with integer coordinates.
  • Output: list of merged segments, each as two endpoints (xa, ya) and (xb, yb) .

Constraints

  • Up to ~10^5 segments.
  • Coordinates fit in 32-bit signed integers.

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.