Neural Network Subnetwork Strength
Updated
Problem statement
A neural network has n neurons numbered from 1 to n.
If the ith neuron has strong connectivity, strongConnectivity[i] = 1. If it has weak connectivity, strongConnectivity[i] = 0.
The neurons form a tree-like network with n - 1 connections, where the ith connection connects neurons neuronFrom[i] and neuronTo[i].
A neuron's strength is defined as the maximum difference between strongly connected and weakly connected neurons in any subnetwork including that neuron.
Return an array of n integers, where the ith integer represents the strength of neuron i.
Note: A subnetwork is a connected subgraph of the given network.
Function
getNeuronStrengths(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 has strong connectivity.
- For neuron
1's strength, consider the subnetwork with neurons1and3:1strong,1weak, so strength is0. - For neuron
2's strength, consider the subnetwork with neurons1,2, and3:1strong,2weak, so strength is-1. - For neuron
3's strength, consider the subnetwork with only neuron3:1strong,0weak, so strength is1. - For neuron
4's strength, consider the subnetwork with only neuron4:0strong,1weak, so strength is-1.
The neuronStrengths array is [0, -1, 1, -1].
More Microsoft Online Assessment questions
- Authentication SystemOA · Seen Nov 2026
- Maximum String OperationsOA · Seen Nov 2026
- 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
Similar questions at other companies
- Minimum Leaf Path Sum over All RootsInfosys · OAInfosys interview questions
- Part 2: Batch Access ReviewScale AI · OAScale AI interview questions
- Binary Tree CamerasAmazon · OA · PHONE SCREEN
- Maximum Sum Path Between Two Leaf NodesGoogle · OAGoogle interview questions
- Tree PointsThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
- Binary Tree Maximum Path SumArcesium · OAArcesium interview questions
- Tree Node With Maximum BeautyC3.ai · OAC3.ai interview questions
- Best Sum Downward Tree PathCitadel · OACitadel interview questions
- Longest Alternating a/b Path in a TreeHudson River Trading · OAHudson River Trading interview questions
- Maximum Reservoir PowerWells Fargo · OAWells Fargo interview questions
Microsoft interview experiences
- Microsoft OA Questions, October 2026: 4 Experiences
- Microsoft Experienced SWE Phone Screen: 1 Experience
- 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)