FastPrepNeural Network Subnetwork Strength
Problems/Neural Network Subnetwork Strength

Neural Network Subnetwork Strength

Microsoft logoMicrosoft● HardOA

Updated Sep 2026

QuestionFunctionExamples

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 neurons 1 and 3: 1 strong, 1 weak, so strength is 0.
  • For neuron 2's strength, consider the subnetwork with neurons 1, 2, and 3: 1 strong, 2 weak, so strength is -1.
  • For neuron 3's strength, consider the subnetwork with only neuron 3: 1 strong, 0 weak, so strength is 1.
  • For neuron 4's strength, consider the subnetwork with only neuron 4: 0 strong, 1 weak, 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)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int[] getNeuronStrengths(int n, int[] neuronFrom, int[] neuronTo, int[] strongConnectivity) {
      // write your code here
    }

}
Checking account…