Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
Updated to Node v18
This comment is hidden because it contains spoiler information about the solution
just because nobody did it for now
Any reason why there is no python translation?
Increased number of tests.
yes some tests are random.
Could possibly use more test cases than 4.
Does it have random tests?
I think this phrase is the problem: "Note that all the streets are bidirectional, if there is a street from p1 to p2 then you can also go from p2 to p1 through this street."
It seems that if you have a street from p1 to p2, then you may assume that you can also return from p2 to p1. Maybe you should explain that all the cities passed to this kata have (explicitly) streets from p1 to p2 and from p2 to p1.
In your example city you can go from p2 to p0 but you cannot go from p2 to p0. To make the problem simpler, I prefered to avoid such cases as explained in the description even if there are algorithm to compute connected components in directed graphs.
Maybe it could be another kata ?
I noticed that some solutions don't pass for the test bellow (with 2 districts).
Test.describe("Streets are bidirectional", function() {
var city = {
'p0': ['p1'],
'p1': ['p0'],
'p3': [],
'p2': ['p0']
};
var nbDistrictFound = countDistricts(city);
var errorMessage = "Expected 2 districts, found " + nbDistrictFound;
Test.expect(nbDistrictFound === 2, errorMessage);
});
It is clear now. Thanks.
Given your question the problem was probably not correctly explained.
A district consists of all the places which are reachable, but not necessarily directly reachable. Since p0, p1 and p2 are reachable they are all in the same district. However, there is no street from p3 to the other places, so it is in another district.
To solve this problem, the order from which you start exploring does not matter.
I changed the description to make the problem more clear, I hope it will help.
It is not clear for me why this city must return 2:
var city = {
'p0': ['p1', 'p2'],
'p1': ['p0'],
'p2': ['p0'],
'p3': []
}
If I start from p0, then I can go to p1 and p2. So there are 3 districts, doesn't it?
But if I start from p3, then there is 1 district.
Shouldn't you describe from where we should start in the city? Or explain that you want the maximum connected districts in the city.