Reported October 2026
Applied Intuitionarray

Merge Collinear Point Segments

Reported by candidates from Applied Intuition's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Applied Intuition OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt on this Applied Intuition problem, reported in October 2026, is grouping lines by slope as a float and calling it done. Parallel lines with different offsets get glued together, and vertical lines blow up on division. This is an interval merge in disguise: normalize each segment to a canonical line key, then sort and merge spans along that line. If you blank on the normalization during the live OA, StealthCoder sits invisibly on your screen as a safety net. Know the shape before you open the problem and it's about 40 lines of code.

The problem

Each input segment is a list of at least two distinct integer points lying on one straight line. Treat its closed geometric span as the interval between its extreme points.
Merge segments that lie on the same infinite line and whose closed spans overlap or touch. A merged result contains the distinct listed points from its component, ordered along a canonical direction. Lines are returned in the order they first appear in the input; disjoint components on one line are returned by increasing position along that line.
The rule applies to every slope, including horizontal and vertical lines.

Function
mergeCollinearSegments(segments: int[][][]) → int[][][]

Examples
Example 1
segments = [[[1,1],[2,2],[4,4]],[[2,1],[4,2]],[[3,3],[6,6]],[[7,7],[8,8]]]
return = [[[1,1],[2,2],[3,3],[4,4],[6,6]],[[7,7],[8,8]],[[2,1],[4,2]]]
The first and third segments overlap on y=x. The later y=x component is disjoint, and the slope-one-half line remains separate.
Example 2
segments = [[[-2,3],[0,3],[2,3]],[[2,3],[5,3]],[[1,-1],[1,2]]]
return = [[[-2,3],[0,3],[2,3],[5,3]],[[1,-1],[1,2]]]
Horizontal segments merge at their touching endpoint, while the vertical segment belongs to another line.

Constraints
1 <= segments.length <= 5000.
Each segment contains at least two distinct points and all of its points are collinear.
The total number of listed points is at most 20000.
Coordinates are integers in [-10^6,10^6].

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is an exact line key. Take any two points of the segment, compute dx and dy, divide both by gcd, and fix the sign so dx > 0, or dx == 0 and dy > 0. Then compute the offset as a cross product, dx*y - dy*x, which stays an integer. Key is (dx, dy, offset). No floats, and vertical and horizontal lines need no special case. Use a dict that preserves first-appearance order of keys. For each line, project points onto a single axis, x, or y if vertical, and keep the span of each segment plus its distinct points. Sort spans, merge when next.start <= current.end (touching counts), and union the point sets. Sort each merged point set along the axis. The pitfall is using < instead of <= and dropping the touching merge from Example 2. Dedupe points with a set. StealthCoder is your hedge if the gcd normalization slips under live pressure.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Merge Collinear Point Segments cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Applied Intuition's OA.

Applied Intuition reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Merge Collinear Point Segments FAQ

What's the core trick in Merge Collinear Point Segments?+

Build an exact integer key for each infinite line using the gcd-reduced direction plus a cross-product offset. Group segments by that key, then run a standard sorted interval merge on each group. The geometry is just a hashing step. The merge itself is the easy part.

Why not group by slope as a float?+

Floats lose precision, and vertical lines divide by zero. Worse, slope alone ignores offset, so two parallel lines would merge wrongly. Use the reduced direction vector with a fixed sign plus the integer offset dx*y - dy*x. That key is exact and handles every orientation.

Do touching endpoints merge?+

Yes. The problem says closed spans that overlap or touch merge. Example 2 shows it at [2,3]. In code, merge when the next start is less than or equal to the current end. Using strict less-than is the classic bug here, and it fails that example.

How do I keep the output order correct?+

Lines come out in first-appearance order, so use an insertion-ordered dict keyed by line. Within each line, components are sorted by position along the axis. Each component's distinct points are sorted the same way. Dedupe with a set before sorting so shared endpoints appear once.

How do I prepare for this in 48 hours?+

Practice interval merging until it's automatic, then practice gcd normalization with sign rules. Write the line-key function from memory and test it on vertical, horizontal, and negative-slope cases. Walk both examples by hand. That covers nearly everything this problem can throw at you.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Applied Intuition.

OA at Applied Intuition?
Invisible during screen share
Get it