Java Code with explanation
For each room we keep track of count of days to reach it.\n\nObservation 1 : when we move from i to (i+1)th room there are even number of visits for all rooms f
For each room we keep track of count of days to reach it.\n\nObservation 1 : when we move from i to (i+1)th room there are even number of visits for all rooms from [0, i] inclusive.\n\nObservation 2: \n```\nif nextVisit[i-1] == i-1\n```\ntwo more days are needed to move to next room\n\nOtherwise if nextVisit[i-1] != i-1 then,\n```\n dp[i] = (dp[i-1] + dp[i-1] - dp[nextVisit[i-1]] + 2 + mod)%mod;\n```\n\n\n```\nclass Solution {\n    public int firstDayBeenInAllRooms(int[] nextVisit) {\n        int rooms = nextVisit.length;\n        long dp[] = new long[rooms];\n        int mod = (int)(1e9)+7;\n        for (int i=1 ; i<rooms ; i++) {\n            if (nextVisit[i-1] == i-1)\n                dp[i] = dp[i-1]+2;\n            else\n                dp[i] = (dp[i-1] + dp[i-1] - dp[nextVisit[i-1]] + 2 + mod)%mod;\n        }\n        return (int)dp[rooms-1];\n    }\n}\n```\n\nUpvote if you understood.\nIf you have doubts i have prepared a video explaining the same on youtube. Hope you like it.
['Java']