Getting TLE - Please Help!!!

Problem:- DIGJUMP

Please help me in optimizing this code which uses BFS to find the shortest distance between start and end vertices.

My code:- Solution

I think your graph construction is wrong .
Lets say
2 2 2 2

So dig[2]={1,2,3,4}
So you do this:
For i=1:

For i=2

Hope it helps.correct me if i am wrong.

But it is giving correct output for all the test cases. Any test cases where it fails?

I am not saying it wont pass.

I am saying that due to this u might be getting tle.
Consider 2 2 2… 10^5 times

So your building graph itself takes O(N^2)

I would suggest try to build the graph properly

Ohh Okay. I will try to implement it differently.