C++ DP beats 99.95% | Python too slow weird
Go back to index equal to nextVisit[i] if nextVisit[i]!=i as time is linear and it takes 2 steps to go forward and make even entries if nextVisit[i]=i . \nC++ -
Go back to index equal to nextVisit[i] if nextVisit[i]!=i as time is linear and it takes 2 steps to go forward and make even entries if nextVisit[i]=i . \nC++ -->\n\n```\nclass Solution {\npublic:\n    int firstDayBeenInAllRooms(vector<int>& nV) {\n        ios_base::sync_with_stdio(false);cin.tie(NULL);\n        int n=nV.size();\n        int mod=1e9+7;\n        vector<long int> dp(n);\n        for (int i=1;i<n;i++){\n            dp[i]=(2*dp[i-1]-dp[nV[i-1]]+2+mod)%mod;\n        }\n        return dp[n-1];\n    }\n};\n```\n\nPython -->\n\n```\nclass Solution:\n    def firstDayBeenInAllRooms(self, nV: List[int]) -> int:\n        n=len(nV)\n        mod=10**9+7\n        dp=[0]*n\n        for i in range(1,n):\n            dp[i]=2*dp[i-1]-dp[nV[i-1]]+2\n        return dp[-1]%mod\n```\n
['Dynamic Programming', 'C', 'Python']