Java solution ✔
logic\n- i have learnt the logic from sandeep jana channel on youtube it has the best explaination \n# code\n\nclass Solution {\n    public int firstDayBeenInAl
# logic\n- i have learnt the logic from sandeep jana channel on youtube it has the best explaination \n# code\n```\nclass Solution {\n    public int firstDayBeenInAllRooms(int[] next) {\n        int i,j,n=next.length;\n        long mod=1000_000_007l;\n        long dp[]=new long[n];\n        dp[0]=0;\n        for(i=1;i<n;i++)\n        {\n            if(next[i-1]==i-1)\n            {\n                dp[i]=(dp[i-1]+2)%mod;\n            }\n            else\n            {\n                dp[i]=(dp[i-1]+dp[i-1]+2-dp[next[i-1]]+mod)%mod;\n            }\n        }\n        return (int)(dp[n-1]%mod);\n    }\n}\n```
['Dynamic Programming', 'Java']