Skip to main content
All Questions

Maximize total preserved credits by fortifying nodes in a tree.

Unlock detailed company stats for this questionUpgrade

Google operates a distributed infrastructure consisting of n interconnected compute nodes. The network forms a tree: there are exactly n - 1 bidirectional communication links and every node is reachable from every other node. Each node i initially contains credits[i] compute credits, which may be positive or negative. To prepare for a planned infrastructure migration, Google may fortify selected nodes. Fortifying a node does not change its own credits; instead, it consumes exactly d compute credits from each of its directly connected neighboring nodes to reinforce its infrastructure. A node may be fortified at most once, and neighboring nodes are allowed to have negative credits after deductions. After the migration, every fortified node remains active, every non-fortified node is decommissioned, and only the final credits of the active (fortified) nodes contribute to the total preserved credits. Determine the maximum total preserved compute credits that can be achieved by choosing an optimal set of nodes to fortify.

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.