Simple C++ Solution
Complexity\n- Time complexity: O(N)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(N)\n Add your space complexity here, e.g. O(n) \n\n# Co
# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int firstDayBeenInAllRooms(vector<int>& nextVisit) {\n        int n = size(nextVisit), mod = 1000000007;\n        vector<vector<long long int>> timeTaken(n+1, vector<long long int>(2, 0));\n        timeTaken[1][0] = 1;\n        timeTaken[1][1] = 2;\n        for(int i=2; i<=n; i++){\n            timeTaken[i][0] = timeTaken[i-1][1] + 1;\n            timeTaken[i][1] = 2*timeTaken[i][0] - timeTaken[nextVisit[i-1]][1] + mod;\n            timeTaken[i][0] %= mod;\n            timeTaken[i][1] %= mod;\n        }\n        return (timeTaken[n][0] - 1 + mod)%mod;\n    }\n};\n```
['C++']