DP Time:O(n), Space: O(n)
class Solution(object):\n    def firstDayBeenInAllRooms(self, nextVisit):\n        """\n        :type nextVisit: List[int]\n        :rtype: int\n        """\n  
class Solution(object):\n    def firstDayBeenInAllRooms(self, nextVisit):\n        """\n        :type nextVisit: List[int]\n        :rtype: int\n        """\n        \n        n = len(nextVisit)\n        \n        if n == 1:\n            return 0\n        \n        \n        dp = [0]*n\n        \n        dp[0] = 0\n        \n        day = 2\n        \n        \n        for i in range(1,n-1):\n            dp[i] = day\n            \n            next_index = nextVisit[i]\n            \n            if next_index == i:\n                day += 2\n            else:\n                next_day = day + 1 + (day - dp[next_index])\n                day = next_day + 1\n        \n        \n        #print dp, day\n        return day%(10**9 + 7)\n                \n            \n            \n            \n        \n
['Dynamic Programming']