Code not working

code not working .

where V=39 , N=8
39 8
9 2 11 5 14 17 8 18

hello @somilgupta4

u r not considering case where ur subproblem is returning INT_MAX

what is the solution for it ?

a) use -1 in place of zero for distingushing visited and non visited states

in line 25 dont add one.

add an if statement after line 25.
if sub !=INT_MAX **
** ans=min(ansm,sub+1)

What difference does it make if i add 1 in line 25 ?

overflow will happen if u add 1 in line 25.
because int_max is the biggest number that int datatype can hold
add one to it will leads to overflow.
that is why i m saying not to add 1 in line 25.

ok thank you so much please tell prateek bhaiya to rectify the code

code is now giving 0 for each test case

pls share ur updated code

check now->

made these changes->

ok thank you so much

the code is not working for the test case V=15 , N=1

please see the test case again 15 1 4

the output is correct,
actually the output it is giving is INT_MAX(2147483647) ,
so this is basically an indication that chnage is not possible.
now it is upto u what u want to print in such cases (check output format of the question)