Get Minimum Servers
Learn this problemProblem statement
In a neural network, there are nodes representing servers capturing neural signals in a cutting-edge machine learning application. Akin to the architecture of a neural network, there are server_nodes servers, where the ith server captures the signal of minimum neural activity represented by minActivity[i]. The servers are connected in a tree structure with server_nodes - 1 connections, where the ith connection connects the servers server_from[i] and server_to[i] and the change in neural activity of the signal traveling the ith connection is represented by server_weight[i].
The neural activity of a signal transmitted from server x and reaching server y is the sum of the neural activity change by traveling across the path from x to y.
Note:
server_weight[i] is positive or negative respectively.
A server u is said to be vulnerable if there exists a server v (!= u) in the subtree of u such that:
v from server u is greater than minActivity[v].
Note: A subtree of a node x is a tree containing all the children of x and having x as the root.
The server can be disconnected in the following way:
The task is to determine the minimum number of servers that need to be disconnected such that no server remains vulnerable.
Function
getMinServers(server_nodes: int, server_from: int[], server_to: int[], server_weight: int[], minActivity: int[]) → int
Complete the function getMinServers in the editor.
getMinServers has the following parameters:
int server_nodes: the number of serversvector: the server from which the signal is sentserver_from vector: the server to which the signal is sentserver_to vector: the change in neural activity due to the signal passing through the serverserver_weight vector: the minimum neural activity that a server can handle without being vulnerableminActivity
Returns
int: the minimum number of servers that need to be disconnected
Examples
Example 1
server_nodes = 5server_from = [1, 1, 3, 3]server_to = [2, 3, 4, 5]server_weight = [-2, 5, -5, -3]minActivity = [0, -10, 5, -5, 5]return = 2
Example 2
server_nodes = 4server_from = [1, 1, 2]server_to = [2, 3, 3]server_weight = [3, 4]minActivity = [1, 2, 3, 4]return = 1Constraints
More Cisco problems
- Collect CoinsSeen Jun 2025
- FizzBuzz ProblemSeen May 2025
- Find Largest Sum Contiguous SubarraySeen May 2025
- Find Largest Sum of Continuous SequenceSeen May 2025
- Find Palindrome Sub-stringSeen May 2025
- Count Numbers with Digit SumSeen Mar 2025
- Maximum Chocolates from Jars (L.C. 198 :)Seen Mar 2025
- Find Elements Largest in Row Smallest in ColumnSeen Mar 2025