All test cases failed for "Knight Moves"

Although, my code is working perfectly fine on local computer and during compilation on CodingBlocks, but all the test cases are failing on submission.

I tried to test this code on leetcode, but on leetcode this question is available for only premium-subscribers.

Can I know what is problem with my solution ?

hello @maheshghamand

pls save ur code here-> https://ide.codingblocks.com/

and share its link with me

saved code here -> link

try this case->
4 7
2 6 2 4

expected is 2
but ur output is -1

Thanks for help, I have done mistake in paragraph on line no 50, now my code is accepted.

But only test case 1 is passing, test case 0, 1 and 3 are giving TLE

Can I improve my code further ?

My code link -> link

yes…no need to explicity construct the graph.

push (s1,s2) tuple in the queue.
then run while loop.
pop the front tuple from the queue and then explore all possible corrdinates from the current coordinate ,update distance if required.
and then push back all the new coordinates in the queue

Thanks for the help, I removed explicit construction of graph -> modified code

But this time, test cases 0, 2 and 3 are giving MLE error.

push child in dq , only if it u r visiting it first time (i,e visited is inf for that child).

This is second time, I fergot to paragraph code well in python. I will be aware next time from such mistakes.

By the way, this time all of my test cases are passed :heavy_check_mark:

Thanks for the help !

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.