Company: Swiggy_9_jan

Difficulty: medium

Problem Statement

Recursive Land Division Recursive Land Division Problem Description A country is made up of N regions, each home to a certain number of towns. The government plans to split the country into two new nations in whichever way keeps the difference between their total town counts as small as possible. The regions are linked by roads forming a tree (an undirected connected graph with N-1 edges and no cycles). Your task is to find the smallest possible absolute difference in town counts between the two resulting nations once exactly one road is removed. Function Description Implement the function minTownDifference . Parameters int N → The number of regions. int[] towns → An array of size N, where towns[i] gives the number of towns in the (i+1)th region. int[][] roads → A list of N-1 pairs, where each pair (u, v) represents a bidirectional road connecting region u and region v . Returns int → The smallest possible absolute difference in town counts between the two new natio

More Swiggy_9_jan OA questionsInterview experiences