Maximum Strength of Every Neuron
Updated
Problem statement
You are given a tree-shaped network of n neurons with n - 1 undirected connections. Connection i joins neurons neuronFrom[i] and neuronTo[i]; neuron labels are 1-based.
Each neuron is either strong or weak:
strongConnectivity[i] = 1means neuroni + 1is strong and contributes+1.strongConnectivity[i] = 0means neuroni + 1is weak and contributes-1.
The score of a connected subnetwork is the number of strong neurons in it minus the number of weak neurons in it.
Return an array neuronStrengths of length n, where neuronStrengths[i] is the maximum score among all connected subnetworks that contain neuron i + 1.
Function
maximumNeuronStrength(n: int, neuronFrom: int[], neuronTo: int[], strongConnectivity: int[]) → int[]Examples
Example 1
n = 4neuronFrom = [1,1,1]neuronTo = [2,3,4]strongConnectivity = [0,0,1,0]return = [0,-1,1,-1]Neuron 3 is strong, so the best connected subnetwork containing it has score 1. Neuron 1 can include neuron 3 for score 0. For either weak leaf, adding the center and the strong neuron still gives score -1, so its best strength is -1.
More Microsoft Online Assessment questions
- Minimum Cost to Process Priority TasksOA · Seen Nov 2026
- Most Visited Sprint MarkerOA · Seen Nov 2026
- Maximum Escape Game ScoreOA · Seen Nov 2026
- Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
- Maximum Interactive Team SizeOA · Seen Nov 2026
- Maximize Pipeline Throughput Under a Scaling BudgetOA · Seen Nov 2026
- Minimum Cost K-Capable ModelsOA · Seen Nov 2026
- Find Available Meeting RoomsOA · Seen Oct 2026
- Maximum Sum of a K-StarOA · Seen Oct 2026
- Capacity to Ship Packages Within DaysOA · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Minimum Leaf Path Sum over All RootsInfosys · OAInfosys interview questions
- Tree Node With Maximum BeautyC3.ai · OAC3.ai interview questions
- Maximum Reservoir PowerWells Fargo · OAWells Fargo interview questions
- Sum of Weighted Distances in a TreeGoogle · ONSITE INTERVIEWGoogle interview questions
- Distance Sums to Special Nodes in a Weighted TreeNutanix · ONSITE INTERVIEWNutanix interview questions
- Part 2: Batch Access ReviewScale AI · OAScale AI interview questions
- Sum Dynamic Weighted Tree DistancesJuspay · OA
- Binary Tree CamerasAmazon · OA · PHONE SCREEN
- Special Diameter EndpointsAgoda · OAAgoda interview questions
- Tree PointsThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
Microsoft interview experiences
- Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
- Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
- Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
- Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
- Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
- Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)