Python | Simple DP | Detailed Explanation
Intuiton: The key to understanding this problem is within the contstraints, each index\'s value can only be equal to the index itself or less. If it is equal to
**Intuiton:** The key to understanding this problem is within the contstraints, each index\'s value can only be equal to the index itself or less. If it is equal to itself, well we know it will always take 2 days. If it is less than itself, well then from a DP approach we will already have data on the day.\n**Solution:** We can think about each index (or day) as how many days it takes to move past it, since days are 0 indexed. The answer will always be the DP value at the 2nd to last day. Since, you can only increment by going forward, we know the minimum stay is 2 days. So at mimum our DP at each index is the previous DP+2. Then if our current value is not equal to its index, we increment our DP by (the previous day DP) minus (the DP of our current value). We do this because that\'s how long it will take for each to get back to the current point.\n\nThis problem is pretty tricky, I think it should be a hard! Hope this helps someone better understand it!\n```\nclass Solution:\n    def firstDayBeenInAllRooms(self, nextVisit: List[int]) -> int:\n        MOD = 10**9 + 7\n        dp = {}\n        dp[-1] = 0\n        dp[0] = 2\n        for ind, n in enumerate(nextVisit[1:], 1):\n            dp[ind] = dp[ind-1]+2\n            if ind != n:\n                dp[ind] = (dp[ind]+dp[ind-1]-dp[n-1])%MOD\n        return dp[len(nextVisit)-2]\n```\n\n\t
[]