Forrest_Gump's blog

By Forrest_Gump, history, 4 years ago, In English

I have commented the code at places. I can't understand why the code gives TLE. 1 test case gives TLE.I have tried to optimise it as much as I could but still TLE. Help would be appreciated. I have used breadth first search to solve the problem.The problem

Also what would be worst case complexity?

Code
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Forrest_Gump (previous revision, new revision, compare).

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Try step by step.

Hint
  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I have marked it visited twice. Even When it is pushed in the queue!

»
4 years ago, # |
  Vote: I like it +4 Vote: I do not like it

This can Help : CF BLOG Instead of storing string in Queue, try generating it when you arrive at the end, for generation of answer string , you can store (parent child )pair in map(STL). For Hint You can check : My Code

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thanks a lot!!! I didn't know about the complexity of adding char to string!

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I have been watching your videos and streams lately they are pretty cool, keep the good work going :)