[Python3] DP O(n)
Explanation\nLet\'s consider dp[i] to be the day on which we reach day i. It depends on when the i-1 will occur again so that we enter i-1th room even times and
**Explanation**\nLet\'s consider dp[i] to be the day on which we reach day i. It depends on when the i-1 will occur again so that we enter i-1th room even times and come to the ith room. To find when the i-1 will occur again we will have to see how many days it took to come from nex[i-1] to i-1 which is dp[i-1]-dp[nex[i-1]]+1. Hence, the day we reach ith room is dp[i-1]+(dp[i-1]-dp[nex[i-1]]+1)+1. \n```\nclass Solution:\n    def firstDayBeenInAllRooms(self, nex: List[int]) -> int:\n        n = len(nex)\n        dp = [0]*n\n        mod  = 10**9+7\n        for i in range(1,n):\n            dp[i] = (dp[i-1]+(dp[i-1]-dp[nex[i-1]]+1)+1)%mod\n        return dp[-1]\n```\n\nIf you like the solution, please consider upvoting.
[]