($leftPoint+1)){ echo PHP_EOL."For row #".$currentRow." left point: ".$leftPoint." right point: ".$rightPoint; for ($currentColumn = $leftPoint+1; $currentColumn < $rightPoint; $currentColumn++) { if (empty($map[$currentColumn][$currentRow])) { $count++; } } } } return $count; } function extractMap(array $levels): array { $map = []; $max = max($levels); $columns = count($levels); for ($i = 0; $i < $columns; $i++) { for ($j = 0; $j < $max; $j++) { $map[$i][$j] = ($levels[$i] <= $j) ? 0 : 1; } } return $map; } for ($i = 0; $i < count($levels); $i++) { echo PHP_EOL."For level #".$i." can be filled is: ".estimate($levels[$i]).PHP_EOL; }