Count Pairs of Connectable Servers in a Weighted Tree Network
A medium-tier problem at 54% community acceptance, tagged with Array, Tree, Depth-First Search. Reported in interviews at UBS and 1 others.
You're asked to count pairs of servers that can connect through a weighted tree network. This problem shows up in interviews at UBS and ThoughtSpot, and it catches people because the naive counting approach either over-counts or misses constraints. The acceptance rate hovers around 54%, which means half the candidates who attempt it don't pass all test cases. The trick isn't just traversing the tree; it's understanding which pairs are actually connectable given the structure and weights. If you hit this live and freeze on the counting logic, StealthCoder surfaces a working solution in seconds, invisible to the proctor.
Companies that ask "Count Pairs of Connectable Servers in a Weighted Tree Network"
Count Pairs of Connectable Servers in a Weighted Tree Network is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by a senior engineer who knows the OA is theater. This is the script.
Get StealthCoderThe trap here is thinking every pair in the tree is connectable. The real work is determining which pairs meet the connectivity constraint, then counting them correctly. Most candidates start with a brute-force DFS or BFS from each server, which is slow and error-prone under pressure. The pattern involves understanding how weights and tree structure interact to define connectivity, then structuring your count to avoid double-counting or missing edges. A solid approach uses DFS to explore reachable nodes from each server while respecting the constraints, then aggregates the count carefully. Common mistakes: forgetting to exclude a server from its own count, miscalculating the graph traversal bounds, or treating the tree as undirected when directionality matters. When you're in the live assessment and the logic gets tangled, StealthCoder runs invisibly and hands you a clean, tested solution so you don't burn time on debug cycles.
Pattern tags
You know the problem.
Make sure you actually pass it.
Count Pairs of Connectable Servers in a Weighted Tree Network recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Count Pairs of Connectable Servers in a Weighted Tree Network interview FAQ
Is this problem still asked at top tech companies?+
Yes. UBS and ThoughtSpot both report asking it. It's not as common as basic tree traversal, but it appears frequently enough in systems and networking-focused roles that you should know the pattern before your OA.
What's the actual trick to solving this efficiently?+
The trick is realizing you need to check connectivity constraints first, then count valid pairs without redundancy. Use DFS to map reachable nodes from each server, but be careful about direction and weight bounds. Most solutions are O(n^2) with smart traversal, not brute force with nested loops.
How does this relate to the topics listed?+
Array holds the server and weight data, Tree is the underlying structure, and DFS is your tool to explore connectivity. The problem is fundamentally about tree traversal with state tracking, which makes DFS the natural fit over BFS.
Why do so many people fail this one if the acceptance rate is 54%?+
Edge cases in counting and misunderstanding the connectivity definition. Candidates often over-count by including reverse pairs, or under-count by missing valid connections. The solution requires careful loop logic and boundary checks.
How much time should I allocate to this in a real assessment?+
Plan for 25 to 35 minutes if you're confident with tree DFS. If you're not solid on recursive traversal and state management, add 10 minutes. If you blank on the pattern, that's when StealthCoder becomes your safety net.
Want the actual problem statement? View "Count Pairs of Connectable Servers in a Weighted Tree Network" on LeetCode →