Easy to Understand Python DP Solution Explained
\nclass Solution:\n    def firstDayBeenInAllRooms(self, nextVisit: List[int]) -> int:\n        N = len(nextVisit)\n        res = [0 for i in range(N)]\n        
```\nclass Solution:\n    def firstDayBeenInAllRooms(self, nextVisit: List[int]) -> int:\n        N = len(nextVisit)\n        res = [0 for i in range(N)]\n        \n        MOD = (10 ** 9 + 7)\n        for i in range(0, N-1):\n            # To reach next node\n            # I am need to reach the current node twice\n            if nextVisit[i] == i:\n                # I can hang around at this node\n                # So to reach next node, I just need to come from 0 to here (res[i] steps), go to here from here (1 step), and go directly to the next node (1 step)\n                res[i+1] = (res[i] + 1 + 1) % MOD\n            else:\n                # I am not allowed to stay at this node\n                # So to reach next node, I need to come from 0 to here (res[i] steps),\n                # then I will get teleported to nextVisit[i] (1 step)\n                # and I will need to come back here from nextVisit[i] (res[i] - res[nextVisit[i]] steps)\n                # Now I would have come to this node twice already, so just need to take 1 more step to the next node\n                res[i+1] = (res[i] + (res[i] - res[nextVisit[i]]) + 2) % MOD\n        \n        return res[-1]\n```
[]