Reported September 2026
Visabreadth first search

Minimize Malware Spread by Removing a Node

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

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

The first attempt at this Visa OA problem, reported in September 2026, usually dies on one wrong assumption: that you should only remove infected servers. The problem says remove exactly one server, infected or not, and example 2 proves it, since the answer is the uninfected hub. With gNodes capped at 500, brute force is fine. Try every removal, run a BFS from the remaining infected servers, count what gets infected, and keep the smallest label on ties. If you freeze on the details, StealthCoder sits invisibly on your screen as a safety net during the live OA.

The problem

There are gNodes servers numbered from 1 through gNodes. The parallel arrays gFrom and gTo describe bidirectional connections: edge i joins gFrom[i] and gTo[i].
The binary array malware describes the initial infection state. Server i is initially infected exactly when malware[i - 1] == 1. An infected server repeatedly infects every directly connected non-infected server until no additional infection is possible.
Before propagation begins, remove exactly one server, whether infected or not, together with all of its incident connections. Return the label of the server whose removal minimizes the number of infected servers remaining after propagation. If several removals produce the same minimum, return the smallest server 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
Removing infected server 3 protects servers 1 and 2. Only servers 4 and 5 become infected, which is fewer than for any other removal.
Example 2
gNodes = 6
gFrom = [1,1,1,1,1]
gTo = [2,3,4,5,6]
malware = [0,1,1,0,0,0]
return = 1
Removing the uninfected center server 1 separates the two infected leaves from every other leaf, leaving only servers 2 and 3 infected.

Constraints
1 ≤ gNodes ≤ 500
0 ≤ gFrom.length = gTo.length ≤ 5000
Every edge endpoint is between 1 and gNodes.
malware.length = gNodes.
Every value in malware is 0 or 1, and at least one server is initially infected.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that nothing clever is required. For each candidate server r from 1 to gNodes, build or reuse an adjacency list, skip r during traversal, and start a multi-source BFS from every infected server that isn't r. Count visited nodes. Track the minimum count, and break ties by smallest label, which a left-to-right loop with a strict less-than gives you for free. The pitfalls are real. Removing an infected server also removes it from the infected count, so don't count it. Don't restrict candidates to infected nodes. Remember the graph may be disconnected and may have duplicate edges. Cost is about N times (N plus E), roughly 500 times 5500, which is easy. If you blank on the loop structure mid-assessment, StealthCoder can hand you the working skeleton so you only verify the tie-breaking and edge cases.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Visa reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimize Malware Spread by Removing a Node FAQ

What's the trick in Minimize Malware Spread by Removing a Node?+

There isn't a deep one. Try every server as the removed node, run a multi-source BFS from the surviving infected servers, count the infected total, and keep the best. The constraints are small enough that this passes without any clever component analysis.

Can I only remove infected servers?+

No. The statement says remove exactly one server, infected or not. Example 2 shows the best answer is uninfected server 1, the hub that connects the infected leaves to the rest. Limiting yourself to infected nodes fails that case.

How do I handle ties?+

Loop candidates from 1 up to gNodes and only update your best when the new infected count is strictly smaller. That keeps the smallest label automatically. If you iterate in another order, add an explicit label comparison.

Is brute force fast enough with gNodes up to 500?+

Yes. Each removal costs one BFS over at most 500 nodes and 5000 edges. Across 500 removals that's a few million operations. Build the adjacency list once and just skip the removed node during traversal.

How should I prepare in 48 hours for this Visa OA?+

Write multi-source BFS on an adjacency list from memory, then add a removed-node skip. Test on both examples, plus a disconnected graph and a case where all infected servers are in one component. Practice the loop-and-compare structure until it's automatic.

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

OA at Visa?
Invisible during screen share
Get it