Sum of Distances to All Nodes in a Tree
Asked at Google · Coding Questions · Difficulty: Hard · Last asked Jan 19, 2026
Given a tree, find for every node the total distance from that node to all the other nodes. This is the quantity used to locate the most central node of a network, for example the best site for a hub that minimises the total travel to all other sites.
Loading the problem…
More Google interview questions
- LLM conceptual questions
- Implement a Nested Tic-Tac-Toe Game Engine
- ML Fundamentals Deep Dive (AI/ML & MLE Roles)
- ML System Design: Recsys, Chatbot, Image Classifier
- Implement Scaled Dot-Product Attention
- Meeting Rooms: Minimum Rooms to Hold All Meetings