Python O(N) Time and O(N) Space Solution
```\nclass Solution:\n    def firstDayBeenInAllRooms(self, nextVisit: List[int]) -> int:\n        #need to keep track of if visit ith room on even day is fine b
```\nclass Solution:\n    def firstDayBeenInAllRooms(self, nextVisit: List[int]) -> int:\n        #need to keep track of if visit ith room on even day is fine but odd day calulate the number\n        #we maintain an array to keep track of the number of days it takes to visit back ith room\n        #again(on second time it is even number)\n        #that can be find out by if nextVisit[i] = j then numDays[j] ... + numDays[i-1]\n        #numDays is the number of days it takes to visit i room again making it even\n        sumUpto = [0 for i in range(len(nextVisit))]\n        sumUpto[0] = 1\n        for i in range(1,len(nextVisit)-1):\n            if nextVisit[i] > 0:\n                sumUpto[i] = 2*sumUpto[i-1] - sumUpto[nextVisit[i]-1] + (i-nextVisit[i]) + 1\n            else:\n                sumUpto[i] = 2*sumUpto[i-1] + i + 1\n\t\t\tsumUpto[i] %= 1000000007\n        return (sumUpto[len(nextVisit)-2] + len(nextVisit)-1) % (1000000007)\n
['Dynamic Programming']