O(n), C++
Main Thing is that, from some index we can go to higher index only when the current index is visited even number of times\nAnother important thing: If we arrive
Main Thing is that, from some index we can go to higher index only when the current index is visited even number of times\nAnother important thing: If we arrive at any index all indexes before it will definintely be traversed even number of times\nLast Thing: Use Prefix array and Don\'t forget to add Mod after prefix[i+1] - prefix[j]\n```\nint Mod = 1000000007;\n    int firstDayBeenInAllRooms(vector<int>& nextVisit) {\n     \n        int n = nextVisit.size();\n        vector<int> prefix(n+1, 0);\n        int j;\n        for(int i=0; i<n; i++)\n        {\n            j = nextVisit[i];\n            if(j==i)\n            {\n                prefix[i+1]=((prefix[i])%Mod + 2)%Mod;\n            }\n            else\n            {\n                int k = ((prefix[i] - prefix[j] + Mod)%Mod + 2)%Mod;\n                prefix[i+1] = ((prefix[i])%Mod + (k)%Mod)%Mod;\n            }\n        }\n        int ans = prefix[n-1]%Mod;\n        cout<<prefix[n-1];\n        return ans;\n    }
[]