Holiday Accommodation Problem

I have confusion in this question.

We use dynamic arrays for visited and count which start from 0 and go to V-1.
But when we are given edges 1-4, and we write in the code that-- visited[4}=true, shouldn’t this be wrong as we are accessing part of the array which is not declared by us and could have any random value.

please solve the problem

please reply its been a day

Hello @amanb25, may be you are getting confused in the indexing. In the question we have been given the statement and the conditions considering the city from 1 and while coding we have shifted the city and instead of starting from 1 we are starting from 0. So you can say that city 1 is now city 0, city 2 is now city 1, city 3 is now city 2, city 4 is now city 3 and so on.
So here the logic in the code is absolutely right.
I hope you were confused with the indexing here we have 4 cities 0,1,2,3.
So do the ques accordingly and the main aim of shifting the city nos. is the array indexing starts from 0 and hence we started with state 0.
Pls feel free to ask if you have any other issues or the confusion.

1 Like