Skip to main content
All Questions

Delete one tree edge to minimize the difference in town totals between the two components.

Unlock detailed company stats for this questionUpgrade

Given a tree graph with N nodes/regions (1 to N) and N-1 bidirectional edges/roads, where region i+1 has towns[i] towns, calculate the minimum difference in total towns between the two resulting components when you delete one edge. Signature: int minTownsDiff(int N, vector<int>& towns, vector<vector<int>>& roads). Example: N=2, towns=[10, 20], roads=[[1, 2]] gives output 10. Constraints: 1 <= N <= 10^5, 1 <= towns[i] <= 10^4.

Format · Google L4 online assessment, December 24, 2025.

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.