All of the perf-tests are failing

Time complexity of my code is O(m+n) but still all of perf-tests are getting timed out error.
I have used ‘set’ to mark the visited nodes.I checked out solutions from previous topic but did not get any solution.
Please help me .

Set is correct way of solving the problem, Note that it’s not the optimal way. When we are talking about performance cases(exponential data) the set operations are considerably slowing down your program. Try to implement it without using any additional data structure in O(M + N) time and O(1) space

P.S : You can argue that both are asymptomatically same(yes I agree),however just understand that judge is little too hard here with instructions.

2 Likes

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.