Golang O(N)
\nvar mod = 1000000007\nfunc firstDayBeenInAllRooms(nextVisit []int) int {\n    next := nextVisit\n    first := make([]int, len(next))\n    res := 0\n    i := 0
```\nvar mod = 1000000007\nfunc firstDayBeenInAllRooms(nextVisit []int) int {\n    next := nextVisit\n    first := make([]int, len(next))\n    res := 0\n    i := 0\n    for i < len(next) - 1 {  \n        first[i] = res % mod // first arrive at room i\n        res =  (res + res - first[next[i]] + 1 + mod) % mod // re-arrive at room i\n        i++\n        res = (res + 1) % mod // move from room i to room i + 1\n    }\n    return res\n}\n```
[]