Python DP O(N) 4-line code
\nclass Solution:\n    def firstDayBeenInAllRooms(self, nextVisit: List[int]) -> int:\n        dp = [0 for _ in range(len(nextVisit))]\n        for idx in range
```\nclass Solution:\n    def firstDayBeenInAllRooms(self, nextVisit: List[int]) -> int:\n        dp = [0 for _ in range(len(nextVisit))]\n        for idx in range(len(nextVisit)-1):\n            dp[idx+1] = (dp[idx]+1) * 2 - dp[nextVisit[idx]]\n        return dp[-1] % 1000000007\n```
['Dynamic Programming', 'Python']