Minimize Malware Spread by Removing a Node

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

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

The twist in this Akuna Capital problem is that the node you remove takes all its edges with it, and every other infected node keeps spreading anyway. Candidates reported it in July 2026. It's a breadth-first-search problem on an undirected graph of up to 2000 servers. You pick the initially infected node whose deletion leaves the fewest infected nodes at the end, and the smallest label wins ties. It looks like a graph puzzle but brute force is allowed. If you blank during the live OA, StealthCoder sits invisibly on your desktop and hands you the approach and code in real time, so you have a hedge. Read the plan below first.

The problem

There are gNodes servers numbered from 1 through gNodes. The parallel arrays gFrom and gTo describe undirected connections: edge i joins gFrom[i] and gTo[i].
The binary array malware describes the initial infection state. Node i + 1 is initially infected exactly when malware[i] == 1.
Before malware spreads, remove exactly one initially infected node and all of its incident connections. Then every infected node repeatedly infects each directly connected non-infected node in the remaining network until no new node can be infected.
Return the label of the removed node that minimizes the total number of infected nodes remaining after propagation. If several removals produce the same minimum, return the smallest node label.

Function
minimizeMalwareSpread(gNodes: int, gFrom: int[], gTo: int[], malware: int[]) → int

Examples
Example 1
gNodes = 9
gFrom = [1,2,4,6,7]
gTo = [2,3,5,7,8]
malware = [0,0,1,0,1,0,0,0,0]
return = 3
Nodes 3 and 5 are initially infected. Removing node 3 prevents infection in the component containing nodes 1 and 2, leaving only nodes 4 and 5 infected. Removing node 5 would leave three infected nodes, so the answer is 3.
Example 2
gNodes = 3
gFrom = [1,2]
gTo = [2,3]
malware = [1,0,1]
return = 1
Removing either initially infected endpoint leaves two infected nodes after propagation. The tie is resolved in favor of the smaller node label, 1.

Constraints
1 <= gNodes <= 2000
gFrom.length == gTo.length
Every edge endpoint is between 1 and gNodes.
malware.length == gNodes
Every value in malware is 0 or 1, and at least one node is initially infected.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that the count includes the other initially infected nodes, so you aren't counting saved nodes, you're counting final infected nodes. With gNodes up to 2000, brute force works. For each infected node, skip it, then run a multi-source BFS from every other infected node over the remaining graph. Count visited nodes. Track the minimum, and break ties by smaller label. Build an adjacency list once, and use a visited array per run. The common pitfalls are off-by-one labels (nodes are 1-indexed, malware is 0-indexed), forgetting to treat the removed node as gone entirely, and returning the index instead of the label. Example 2 is your tie test. A union-find solution is faster, but it's easier to get wrong under pressure. If the clock is ugly and your mind goes blank, StealthCoder is the safety net on the live OA. Otherwise, write the BFS loop.

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 Minimize Malware Spread by Removing a Node 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 minimize malware spread ii. If you have time before the OA, drill that.

⏵ The honest play

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

Akuna Capital 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.

Minimize Malware Spread by Removing a Node FAQ

How hard is Minimize Malware Spread by Removing a Node really?+

Medium-hard on paper, easy if you accept brute force. The constraints cap gNodes at 2000, so running one BFS per infected node is fine. The difficulty is reading the statement correctly: the removed node disappears with its edges, and other infected nodes still spread.

What's the trick to solving it?+

Stop trying to be clever. For each initially infected node, mark it blocked, then BFS from all remaining infected nodes at once and count how many nodes get reached. Keep the best count and the smallest label on ties. The optimization via union-find is optional.

Is this graph pattern still asked at Akuna Capital?+

It was reported in July 2026, so it's recent. Graph traversal problems like BFS and DFS on component spread show up often in assessments, so expect variants. Know how to build an adjacency list from parallel edge arrays and run a traversal from multiple sources.

What mistakes lose points on this problem?+

Mixing indexing is the big one. Node labels run 1 to gNodes, but malware[i] refers to node i + 1. Others: not excluding the removed node from traversal, forgetting to count the surviving infected seeds, and returning the count instead of the node label. Test Example 2 for the tie rule.

How do I prepare for this in 48 hours?+

Write a multi-source BFS on an adjacency list from scratch twice. Then code this problem with a blocked node and hand-trace both examples. Check that example 1 returns 3 and example 2 returns 1. Then skim a union-find version so you recognize the faster approach, but submit the BFS.

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

OA at Akuna Capital?
Invisible during screen share
Get it