Minimize Malware Spread by Removing a Node
Updated
Problem statement
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[]) → intExamples
Example 1
gNodes = 9gFrom = [1,2,4,6,7]gTo = [2,3,5,7,8]malware = [0,0,1,0,1,0,0,0,0]return = 3Nodes 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 = 3gFrom = [1,2]gTo = [2,3]malware = [1,0,1]return = 1Removing 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 <= 2000gFrom.length == gTo.length- Every edge endpoint is between
1andgNodes. malware.length == gNodes- Every value in
malwareis0or1, and at least one node is initially infected.
More Akuna Capital Online Assessment questions
- Last Digit of the Ways to Split Traders Between Two OfficesOA · Seen Dec 2026
- Light Bulbs Left On After All Engineers FinishOA · Seen Dec 2026
- Delivery Management SystemOA · Seen Nov 2026
- Count Server ReplacementsOA · Seen Nov 2026
- Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximum Remaining Drone PowerOA · Seen Nov 2026
- Rolling MetricsOA · Seen Oct 2026
- Vowel Substring GameOA · Seen Sep 2026
- Competitive ForagingOA · Seen Sep 2026
- Binary CircuitOA · Seen Sep 2026
Similar questions at other companies
- Minimize Malware Spread by Removing a NodeVisa · OAVisa interview questions
- Reaching Points with Perfect-Square ObstaclesIMC Trading · OAIMC Trading interview questions
- Satellite Network Message PropagationOptiver · OAOptiver interview questions
- Explore an Unknown Grid and Find a PathLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Retryable URL MazeRamp · PHONE SCREENRamp interview questions
- Xiangqi Horse ReachabilityeBay · PHONE SCREENeBay interview questions
- Repeated-Roll Teleporter ReachabilitySplunk · PHONE SCREENSplunk interview questions
- Generate a Connected Graph and Find a Shortest PathThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
- Shortest Path Around Moving ParadesZip · PHONE SCREENZip interview questions
- Concurrent Web Crawler SimulationOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
Akuna Capital interview experiences
- Akuna Capital Quant Trader and QR Interviews: 5 Experiences
- Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
- Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
- Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
- Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)
- Akuna Capital QR Coding Interviews: 17 Experiences (Part 2 of 6)