Java O(N) | space O(N), DP  (modified  prefixSum)
Let\'s organize buffer array, where buffer[room] has a number of total days that are needed to leave exact room\n- if we face the room with i==nextVisit[i], the
- Let\'s organize buffer array, where buffer[room] has a number of total days that are needed to leave exact room\n- if we face the room with i==nextVisit[i], then certainly to leave that room we need take into consideration previous room total days number + 2\n- if we face the room with i<nextVisit[i], then we have to take into consideration : previous room total days number + 1 (the first odd attempt in the current room) + number of days between nextVisit[i] index room (nearest room to the current room) and previous room + 1 (the second even attempt in the curent room)\n```\n    public int firstDayBeenInAllRooms(int[] nextVisit) {\n        final long mod = 1000000007L;\n        int len = nextVisit.length;\n        long[] prefixSum = new long[len+1];\n\n        for(int i=0;i<len;i++){\n            if(nextVisit[i]==i)\n                prefixSum[i+1] = prefixSum[i-1+1] + 2;\n            else\n                prefixSum[i+1] = (mod + prefixSum[i-1+1] + 1 + prefixSum[i-1+1] - prefixSum[ nextVisit[i]-1+1 ] + 1)%mod;\n        }\n        return (int) prefixSum[len-1];\n    }\n```\n\n\n\n\n\nOptimized version:\n```\n    public int firstDayBeenInAllRooms(int[] nextVisit) {\n        final long mod = 1000000007L;\n        int len = nextVisit.length;\n        long[] prefixSum = new long[len+1];\n\n        for(int i=0;i<len;i++)\n                prefixSum[i+1] = (mod + prefixSum[i-1+1] + 1 + prefixSum[i-1+1] - prefixSum[ nextVisit[i]-1+1 ] + 1)%mod;\n        \n        return (int) prefixSum[len-1];\n    }\n```\n\nEven more optimized version :)\n```\n    public int firstDayBeenInAllRooms(int[] nextVisit) {\n        final long mod = 1000000007L;\n        int len = nextVisit.length;\n        long[] prefixSum = new long[len+1];\n\n        for(int i=0;i<len;i++)\n                prefixSum[i+1] = (mod + prefixSum[i]*2 - prefixSum[ nextVisit[i] ] + 2)%mod;\n        \n        return (int) prefixSum[len-1];\n    }\n```
[]