Company: Sprinklr
Difficulty: medium
Odd Count You are given an undirected tree: N nodes connected by N-1 edges, with no cycles or self-loops, and the whole structure is connected. No node carries any value on its own. Each edge, however, can be labeled with a weight of either 1 or 2, and you are free to choose that weight independently for every edge. For two nodes u and v, define the path sum between them as the sum of the weights assigned to every edge lying on the unique path connecting u and v. You must answer Q queries, each giving two integers a and b. For each query, count how many distinct ways of assigning weights (1 or 2) to all edges make the path sum between a and b come out odd. Report each count modulo 10 9 +7. Function Description Complete the solve function. This function takes the following 4 parameters and returns an array containing answers for Q queries: N : Represents the value of a number Edges : Represents a 2D array of integers representing the edges of the graph Q : Represents the size of the que