Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
The only way to get to room i+1 is when you are visiting room i and room i has been visited an even number of times.
After visiting room i an odd number of times, you are required to visit room nextVisit[i] where nextVisit[i] <= i. It takes a fixed amount of days for you to come back from room nextVisit[i] to room i. Then, you have visited room i even number of times.nextVisit[i]
Can you use Dynamic Programming to avoid recomputing the number of days it takes to visit room i from room nextVisit[i]?