Yuck
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nimport java.util.*;\n\npublic class Solution {\n\n    // i - room id\n    // odd  => 0...next[i]\n    // even => (i+1) % n\n\n    // observations: we want to go forward only, best is always pick next[i] and never any smaller!\n    // once we get sent back from i to next[i] we need to walk again the same path\n    // forward until we get to i again, to make cnt[i] EVEN, then we move to i + 1\n    // cache the calculations from next[i] to i\n\n    // dp[i] = dp[i - 1] + dp[i - 1] + 1 - dp[next[i]] + 1\n    // LOGIC: to get to A[i] we need to get to A[i - 1] EVEN num of times and then 1 step to A[i] += A[i - 1] * 2 + 1\n    // BUT the second time we get to A[i - 1] we do not walk from 0 but from A[next[i]] so -= that cost but add +1\n    // for the redirect which throws us backwards\n    public int firstDayBeenInAllRooms(int[] nextVisit) {\n        int[] dp = new int[nextVisit.length];\n        int M = 1000000007;\n        for (int i = 1; i < dp.length; i++) {\n            int steps = 2 * dp[i - 1] - dp[nextVisit[i - 1]] + 2;\n            dp[i] = steps < 0 ? (steps + M) % M : steps % M;\n        }\n        return dp[dp.length - 1];\n    }\n\n}\n\n```
['Java']