MEDIUMasked at 5 companies

Number of Operations to Make Network Connected

A medium-tier problem at 65% community acceptance, tagged with Depth-First Search, Breadth-First Search, Union Find. Reported in interviews at McKinsey and 4 others.

Founder's read

You've got a graph with n computers and some are disconnected. You need to find the minimum number of cables to rewire so everything talks to everything else. McKinsey, Akuna Capital, Intuit, IBM, and Nvidia have all asked this one. The trap is thinking you need to rebuild the whole graph instead of just identifying and connecting the isolated islands. Acceptance rate sits at 65 percent, which means most people who see it get it, but the ones who don't usually miss the real insight. If this lands in your assessment and you blank on the pattern, StealthCoder runs invisibly during your screen share and delivers a working solution in seconds.

Companies asking
5
Difficulty
MEDIUM
Acceptance
65%

Companies that ask "Number of Operations to Make Network Connected"

If this hits your live OA

Number of Operations to Make Network Connected is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know.

Get StealthCoder
What this means

This is a graph connectivity problem masquerading as a shortest-path or greedy problem. The pattern is simple once you see it: count how many connected components you have, then you need exactly (components minus 1) operations to fuse them all together. The two common mistakes are trying to apply Dijkstra or thinking you're optimizing cable placement instead of just counting islands. Union Find or DFS both work fine here, but candidates often overcomplicate the solution logic. The second trap is not checking if the problem is even solvable first (you need at least n-1 edges to have any hope). StealthCoder is your safety net if you waste time chasing the wrong algorithmic path. The real work is recognizing this is Union Find territory and counting components, not finding shortest paths.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Number of Operations to Make Network Connected recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Number of Operations to Make Network Connected interview FAQ

Is this really a medium problem or does it feel harder?+

At 65 percent acceptance, it's legitimately medium. Most engineers see 'graph' and jump to DFS or BFS to count components, which works and is fast enough. The hard part is resisting the urge to overthink it as a pathfinding problem. Once you realize it's just counting islands, the code is straightforward.

Union Find vs DFS, which should I use?+

Both work, but Union Find is cleaner for this specific problem since you're merging components. DFS also counts components correctly and uses less code overhead. Pick whichever you're more comfortable coding under pressure. The algorithmic insight matters more than the tool.

What's the actual trick Nvidia and Intuit care about?+

They care that you recognize this as a component-counting problem, not a pathfinding problem. The trick is the math: if you have k components, you need exactly k-1 operations to connect them all. Miss that, and you'll overthink the solution.

How does this relate to the Union Find and Graph topics together?+

Union Find is specifically designed for component problems. You union nodes as you traverse edges, and at the end you count disjoint sets. It's the algorithmic sweet spot for this problem. Graph knowledge alone isn't enough, you need to know when to apply Union Find.

What's the failure mode if I don't check solvability first?+

If n computers need n-1 cables minimum to be fully connected, but you only have fewer edges to work with, the answer is -1 (impossible). Candidates often miss this edge case and return a positive count when they should return -1, which fails test cases immediately.

Want the actual problem statement? View "Number of Operations to Make Network Connected" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.