Typescript | DP + Iterative + Beats 100.00% + Time: O(nk^2) - Space: O(k)
Time: O(nk^2)\nSpace: O(k)\nLanguage: javascript, typescript\n\nRuntime: 325 ms, faster than 100.00%\nMemory Usage: 45.1 MB, less than 100.00%\n\n\nfunction max
Time: O(nk^2)\nSpace: O(k)\nLanguage: javascript, typescript\n\nRuntime: 325 ms, faster than 100.00%\nMemory Usage: 45.1 MB, less than 100.00%\n\n```\nfunction maxValueOfCoins(piles: number[][], coins: number): number {\n    let dp = new Array(coins + 1).fill(0);\n    \n    for (let i = 0; i < piles.length; ++i) {\n\t    for (let j = coins; j > 0; --j) {\n\t\t\t// "sum" is a count of coins from piles[i]\n            let sum = 0;\n\n            for (let k = 1; k <= Math.min(j, piles[i].length); k++) {\n                sum += piles[i][k - 1];\n\n\t\t\t\t// take "k" coins from piles[i] and the previous best "j-k" coins\n                dp[j] = Math.max(dp[j], dp[j-k] + sum);\n            }\n        }\n    }\n    \n    return dp[coins];\n}\n```
['Dynamic Programming', 'Iterator', 'TypeScript', 'JavaScript']