All perf test cases are failing

I checked one of the test case and it says it’s wrong output. I’ve used multi source BFS approach and marked the nodes once visited. Any hints would be appreciated

You don’t need to mark the nodes as visited. Because initially all empty rooms has a value of INF. And your code just have to cover all reachable rooms. Now lets say initially in the queue you have a point with 0. Now BFS starts and you remove that point and travel in all four possible direction and set the distance of empty room w.r.t. this point and then put this new room to the queue. This way only empty rooms will be visited and there distance will be set as minimum as possible. And the rooms which cannot be visited will remain as INF. Hope this helps.

Hey, this helped. Thanks!

1 Like

Closing this topic as your issue has been resolved by the community. If not Kindly un-mark the accepted solution to re-open the topic or feel free to create a new topic and post a link to this topic as a reference.