here is the link for the question :
here is my code.
i have used simple BFS starting from the first index and going till the last index.
this solution is passing all the test cases except for the last test case which shows time limit exceeded on submission but when i copy the testcase and run it, it gives some runtime error which i am not able to fix. can you please check what is the problem in my code?