HarshCasper / NeoAlgo

Bringing all Data Structures and Algorithms under one Roof ⚡
MIT License
875 stars 1.05k forks source link

Ninja and cities #7519

Closed ishwari20 closed 3 years ago

ishwari20 commented 3 years ago

Have you read the Contributing Guidelines on Pull Requests?

Yes

Description

Ninja decided to find the distance between the neighbouring cities and then store them for future use. He took data from the map and developed an input format. He is given an integer ‘N’ denoting the number of cities and then he has an array of size ‘N - 1’ that stores a pair of numbers at each index. Let the pair be ‘I1’ and ‘I2’, which will denote a bidirectional edge between the two cities ‘I1’ and ‘I2’. A subtree is a subset of cities, where each city can be reached from every other city of the subset. The path between each pair passes only though the cities present in the subset. Two subtrees are taken differently if there are one or more cities in one subtree not present in the other. Now, you need to create an array of ‘N - 1’ elements where the ‘ith’ element is the number of subtrees in which the maximum distance between any two cities is equal to ‘i’.

Checklist

Related Issues or Pull Requests

Issue #7516