Swift DP
Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\nswift []\nclass Solution {\n    func firstDayBeenInAllRooms(_ nextVisit: [Int]) -> In
# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```swift []\nclass Solution {\n    func firstDayBeenInAllRooms(_ nextVisit: [Int]) -> Int {\n        let n = nextVisit.count\n        var days: [Int] = Array(repeating: 0, count: n)\n        let mod = Int(pow(10, 9) + 7)\n        for i in 1..<n {\n            days[i] = (2 * (days[i - 1] + 1) - days[nextVisit[i - 1]]) % mod\n             if days[i] < 0 {\n                days[i] += mod\n            }\n        }\n\n        return days[n - 1]\n    }\n}\n```
['Dynamic Programming', 'Swift']