Easy to understand JavaScript solution (DP)
Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n\nvar firstDayBeenInAllRooms = function(nextVisit) {\n    const MODULO = 10 ** 9 + 
# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```\nvar firstDayBeenInAllRooms = function(nextVisit) {\n    const MODULO = 10 ** 9 + 7;\n    const size = nextVisit.length;\n    const visitDay = Array(size).fill(0);\n\n    for (let index = 1; index < size; index++) {\n        const previousRoom = index - 1;\n        const day = visitDay[previousRoom];\n        const oddTimes = day - visitDay[nextVisit[previousRoom]] + 1;\n        const evenTimes = day + 1;\n\n        visitDay[index] = (oddTimes + evenTimes + MODULO) % MODULO;\n    }\n    return visitDay[size - 1];\n};\n```
['JavaScript']