Java solution 100% faster Using DP Tabulation
Explatation in comments.\nPlease Upvote if you undrstand this.\n...\nclass Solution {\n\n\tpublic int minimumWhiteTiles(String floor, int numCarpets, int carpet
Explatation in comments.\nPlease **Upvote** if you undrstand this.\n...\nclass Solution {\n\n\tpublic int minimumWhiteTiles(String floor, int numCarpets, int carpetLen) {\n\t\n\t\tchar[] arr = floor.toCharArray();\n\t\t\n\t\tint n = arr.length;\n\t\t//using dp\n\t\t\n\t\tint[][] dp = new int[numCarpets + 1][n + 1];\n\t\t//dp[i][j] -> no of whites in arr(0, i) when j carpet is used\n\t\t//row -> number of carpets\n\t\t//columns -> arr / floor\n        \n        for(int i = 0; i <= numCarpets; i++){\n            for(int j = 1; j <= n; j++){\n                if(i == 0)\n                    dp[i][j] = dp[i][j - 1] + (arr[j - 1] - \'0\');\n                else if(j <= carpetLen)//cover all floor\n                    dp[i][j] = 0;\n                else{\n                    int w = Math.min(dp[i - 1][j - carpetLen], dp[i - 1][j]);\n                    //minimum no of whites if only j - 1 carpet is used already\n\t\t\t\t\t//we want to minimize whites by using or not using jth carpet\n                    \n                    //dp[i][j - 1] -> minimum no of moves if we used i carpets already\n\t\t\t\t\t//arr[j - 1] - \'0\' -> adds white count for j - 1 th char\n\t\t\t\t\t\n                    int min = Math.min(w, dp[i][j - 1] + (arr[j - 1] - \'0\'));\n                    //minimum whites in any case\n                    \n                    dp[i][j] = min;//update\n                }\n            }\n        }\n        \n        return dp[numCarpets][n];\n    }\n}\n...
['Array', 'Dynamic Programming', 'Java']