Easy & More Optimized JavaScript Solution Using Dynamic Programming
Time complexity:\n Add your time complexity here, e.g. O(n) \n    O(n)\n\n# Space complexity:\n Add your space complexity here, e.g. O(n) \n    O(n)\n\n# Code\n
# Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(n)\n\n# Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(n)\n\n# Code\n```\n/**\n * @param {number} n\n * @param {number} k\n * @param {number} maxPts\n * @return {number}\n */\nvar new21Game = function(n, k, maxPts) {\n    if (k == 0 || n >= k + maxPts) return 1.0;\n    let sum = 1.0;\n    let result = 0.0;\n    let dp = new Array(n + 1);\n    dp[0] = 1.0;\n    for (let i = 1; i <= n; i++) {\n        dp[i] = sum / maxPts;\n        if (i < k) sum += dp[i];\n        else result += dp[i];\n        if (i - maxPts >= 0) sum -= dp[i - maxPts];\n    }\n    return result;\n};\n```
['Math', 'Dynamic Programming', 'Sliding Window', 'Probability and Statistics', 'JavaScript']