PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Applied

Merge Overlapping Collinear Segments

Last updated: Apr 24, 2026

Quick Overview

This question evaluates computational geometry and algorithm design skills, focusing on collinearity testing, projecting points onto a line, merging overlapping 1D intervals generalized to arbitrary lines, ordering points along a line, and handling duplicates and edge cases.

  • hard
  • Applied
  • Coding & Algorithms
  • Software Engineer

Merge Overlapping Collinear Segments

Company: Applied

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You are given a list of 2D geometric segments: `vector<vector<pair<double, double>>> segments` Each inner list represents one segment and contains at least two points. All points within the same segment are collinear, but: - the points may appear in any order, - a segment may include interior points in addition to its endpoints, - the segment may be horizontal, vertical, or diagonal. Two segments should be merged if they lie on the same infinite line and their 1D projections on that line overlap or touch. If multiple segments can be merged transitively, merge them into one result. For each merged segment, return all unique points that appeared in any of the original segments that were merged, ordered along the line from one end of the merged segment to the other. Do not merge segments that merely intersect at a point but are not on the same line. Example: Input: `[ [(1,1), (2,2), (4,4)], [(4,2), (2,1)], [(7,7), (8,8)], [(3,3), (5,5)] ]` Output: `[ [(1,1), (2,2), (3,3), (4,4), (5,5)], [(2,1), (4,2)], [(7,7), (8,8)] ]` Assume exact geometric comparisons are acceptable for this problem.

Quick Answer: This question evaluates computational geometry and algorithm design skills, focusing on collinearity testing, projecting points onto a line, merging overlapping 1D intervals generalized to arbitrary lines, ordering points along a line, and handling duplicates and edge cases.

Related Interview Questions

  • 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)
  • Find first and last occurrence in sorted array - Applied (medium)
Applied logo
Applied
Apr 15, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
4
0

You are given a list of 2D geometric segments:

vector<vector<pair<double, double>>> segments

Each inner list represents one segment and contains at least two points. All points within the same segment are collinear, but:

  • the points may appear in any order,
  • a segment may include interior points in addition to its endpoints,
  • the segment may be horizontal, vertical, or diagonal.

Two segments should be merged if they lie on the same infinite line and their 1D projections on that line overlap or touch. If multiple segments can be merged transitively, merge them into one result.

For each merged segment, return all unique points that appeared in any of the original segments that were merged, ordered along the line from one end of the merged segment to the other.

Do not merge segments that merely intersect at a point but are not on the same line.

Example:

Input: [ [(1,1), (2,2), (4,4)], [(4,2), (2,1)], [(7,7), (8,8)], [(3,3), (5,5)] ]

Output: [ [(1,1), (2,2), (3,3), (4,4), (5,5)], [(2,1), (4,2)], [(7,7), (8,8)] ]

Assume exact geometric comparisons are acceptable for this problem.

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.