We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
just change your weightedu method to this. You forgot an if check. your answers were coming wrong because in some cases when x and y belonged to the same country, you were doing the union and it was making the sum of that country 0.
after fixing that when you run your code, you will get a timeout. that is because you have a nested loop inside calculating the answer. instead replace it with the simple efficient single loop.
Journey to the Moon
You are viewing a single comment's thread. Return to all comments →
hey I guess I found your bug!
just change your weightedu method to this. You forgot an if check. your answers were coming wrong because in some cases when x and y belonged to the same country, you were doing the union and it was making the sum of that country 0.
after fixing that when you run your code, you will get a timeout. that is because you have a nested loop inside calculating the answer. instead replace it with the simple efficient single loop.
and there you go! solved!