Efficient JS solution - DP (Beat 100% time)
\n\nPro tip: Love lil Xi\xE8 \uD83D\uDC9C \u7231\u5C0F\u8C22 \uD83D\uDC9C\n\n# Complexity\n- let n = floor.length, c = numCarpets\n- Time complexity: O(nc)\n- S
![image.png](https://assets.leetcode.com/users/images/197c73b5-11df-4d7f-a64a-0922789cc1b7_1705598883.7087042.png)\n\nPro tip: Love lil Xi\xE8 \uD83D\uDC9C \u7231\u5C0F\u8C22 \uD83D\uDC9C\n\n# Complexity\n- let `n = floor.length`, `c = numCarpets`\n- Time complexity: $$O(nc)$$\n- Space complexity: $$O(nc)$$\n\n# Code\n```js\nlet dp = Array.from({ length: 1001 }, () => new Uint32Array(1001));\n\n/**\n * @param {string} floor\n * @param {number} numCarpets\n * @param {number} carpetLen\n * @return {number}\n */\nvar minimumWhiteTiles = function (floor, numCarpets, carpetLen) {\n  let n = floor.length;\n  let all = 0;\n  let sum = 0;\n  for (let i = 0; i < n; ++i) {\n    all += floor.charCodeAt(i) & 1;\n    sum += floor.charCodeAt(i) & 1;\n    if (i >= carpetLen) sum -= floor.charCodeAt(i - carpetLen) & 1;\n\n    for (let j = 0; j <= numCarpets; ++j) {\n      if (!j) {\n        dp[i][j] = 0;\n        continue;\n      }\n      if (i < carpetLen) {\n        dp[i][j] = sum;\n        continue;\n      }\n      dp[i][j] = Math.max(dp[i - 1][j], dp[i - carpetLen][j - 1] + sum);\n    }\n  }\n\n  return all - dp[n - 1][numCarpets];\n};\n```
['Dynamic Programming', 'JavaScript']