✔ Python3 Solution | O(n) Time & Space | DP
Complexity\n- Time complexity: O(n)\n- Space complexity: O(n)\n\n# Solution 1\n\nclass Solution:\n    def dieSimulator(self, n, A):\n        dp = [[0] * 7 for _
# Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(n)$$\n\n# Solution 1\n```\nclass Solution:\n    def dieSimulator(self, n, A):\n        dp = [[0] * 7 for _ in range(n + 1)]\n        dp[0][-1] = 1\n        for i in range(1, n + 1):\n            for j in range(6):\n                dp[i][j] = dp[i - 1][-1]\n                if i > A[j]: dp[i][j] -= dp[i - A[j] - 1][-1] - dp[i - A[j] - 1][j]\n            dp[i][-1] = sum(dp[i]) % (10 ** 9 + 7)\n        return dp[-1][-1]\n```\n\n# Solution 2\n```\nclass Solution:\n    def dieSimulator(self, n, A):\n        dp = [[0] * 6 + [1]]\n        for i in range(n):\n            dp.append([dp[i][-1] - (dp[i - A[j]][-1] - dp[i - A[j]][j] if i >= A[j] else 0) for j in range(6)])\n            dp[-1].append(sum(dp[-1]) % (10 ** 9 + 7))\n        return dp[-1][-1]\n```
['Dynamic Programming', 'Python3']