| Conditions | 6 |
| Paths | 11 |
| Total Lines | 21 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | public static function heightChecker(array $heights): int |
||
| 10 | { |
||
| 11 | if (empty($heights)) { |
||
| 12 | return 0; |
||
| 13 | } |
||
| 14 | $map = array_fill(0, 101, 0); |
||
| 15 | foreach ($heights as $height) { |
||
| 16 | $map[$height]++; |
||
| 17 | } |
||
| 18 | [$prev, $curr] = [0, 1]; |
||
| 19 | foreach ($heights as $height) { |
||
| 20 | while ($map[$curr] === 0) { |
||
| 21 | $curr++; |
||
| 22 | } |
||
| 23 | if ($curr !== $height) { |
||
| 24 | $prev++; |
||
| 25 | } |
||
| 26 | $map[$curr]--; |
||
| 27 | } |
||
| 28 | |||
| 29 | return $prev; |
||
| 30 | } |
||
| 49 |