2
Map<String, Integer> cache;4
public int minimumWhiteTiles(String floor, int numCarpets, int carpetLen) {5
cache = new HashMap<>();6
return helper(floor, 0, numCarpets, carpetLen);9
public int helper(String floor, int position, int numCarpets, int carpetLen) {10
if (position >= floor.length()) {14
if (floor.length() - position <= numCarpets * carpetLen) {18
String key = position + ", " + numCarpets;19
if (cache.containsKey(key)) {20
return cache.get(key);23
if (numCarpets == 0) {24
int output = floor.charAt(position) - '0' + helper(floor, position + 1, 0, carpetLen);26
cache.put(key, output);32
floor.charAt(position) - '0' + helper(floor, position + 1, numCarpets, carpetLen),33
helper(floor, position + carpetLen, numCarpets - 1, carpetLen));35
cache.put(key, output);