you are pushing the same variable twice on the queue list. For example, in the second test case: initially qq = {0}; after loop 1, qq = {1,2}; after loop 2, qq = {2,2}, which is incorrect; add a variable done[] to avoid this. This passes the given test cases answered 23 Jul '15, 16:50
Thanks, this now passes the given test cases, but not the problem. Can you tell me where else I have made mistake?
(23 Jul '15, 20:09)
