Reported February 2026
IBMunion find

Minimum Number of Non-Empty Disjoint Segments

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

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

IBM's February OA included a union-find problem asking you to find the minimum number of non-empty disjoint segments. You're likely facing this in the next 48 hours. The trap is overthinking the segmentation logic. The real insight is recognizing when segments can be merged or when they must stay separate. Union-find is the pattern, but the problem hinges on understanding what "disjoint" means in the specific context IBM sets up. This is a connectivity problem disguised as an optimization question.

Pattern and pitfall

The core trick here is that you need to identify which elements belong to the same segment and which don't. Union-find (disjoint set union) lets you efficiently group connected components. The catch: you have to figure out the rule for when two elements should be in the same segment. Often it's based on proximity, a value threshold, or an explicit constraint in the problem. Build the union-find structure, count the number of distinct components at the end, and that's your answer. The secondary pitfall is not handling path compression or union by rank, which tanks your runtime. StealthCoder can spot this pattern instantly and feed you the template if you blank on the merging logic during the live assessment.

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 Minimum Number of Non-Empty Disjoint 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

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as number of connected components in an undirected graph. If you have time before the OA, drill that.

⏵ The honest play

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

IBM 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.

Minimum Number of Non-Empty Disjoint Segments FAQ

Is this a straightforward union-find template problem?+

Mostly, but with a twist. You'll need to figure out the merging condition from the problem context. It's not just 'connect A and B.' There's logic about when segments are allowed to merge. Once you nail that, the union-find structure is standard.

What's the time complexity I should aim for?+

O(n * alpha(n)) where alpha is the inverse Ackermann function. With path compression and union by rank, this is near-constant. Avoid O(n^2) naive union logic or you'll timeout on large inputs.

How do I figure out the merging condition if the problem isn't explicit?+

Read the problem constraints carefully. Look for clues about adjacency, value differences, or indexing rules. Often it's 'merge if distance is <= k' or 'merge if values are equal.' That condition is the entire problem.

Should I pre-sort or pre-process the input?+

Probably yes. Many union-find problems require sorting by value or distance first. This changes which pairs you consider for merging. Check if the order of operations matters before you code.

How do I count the final segments?+

After all unions, iterate through every element and count how many have themselves as their root (find(i) == i). That count is your answer. Don't recount during the union phase.

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

OA at IBM?
Invisible during screen share
Get it