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.


