×

 0 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 asked 22 Nov '17, 15:48 2★ramini 61●5 accept rate: 8%

 0 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: Adj[1]=2,3,4 Adj[2]=1 Adj[3]=1 Adj[4]=1 For i=2 Adj[1]={2,3,4,2} Adj[2]={1,1,3,4} ... Hope it helps.correct me if i am wrong. answered 23 Nov '17, 10:46 1.6k●2●9 accept rate: 23% But it is giving correct output for all the test cases. Any test cases where it fails? (23 Nov '17, 21:13) ramini2★ 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 (23 Nov '17, 21:45) Ohh Okay. I will try to implement it differently. (24 Nov '17, 00:42) ramini2★
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×22
×7

question asked: 22 Nov '17, 15:48

question was seen: 269 times

last updated: 24 Nov '17, 00:42