| Conditions | 6 |
| Paths | 11 |
| Total Lines | 22 |
| Code Lines | 14 |
| 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 | $n = count($heights); |
||
| 15 | $map = array_fill(0, $n + 1, 0); |
||
| 16 | foreach ($heights as $height) { |
||
| 17 | $map[$height]++; |
||
| 18 | } |
||
| 19 | [$prev, $curr] = [0, 1]; |
||
| 20 | foreach ($heights as $height) { |
||
| 21 | while ($map[$curr] === 0) { |
||
| 22 | $curr++; |
||
| 23 | } |
||
| 24 | if ($curr !== $height) { |
||
| 25 | $prev++; |
||
| 26 | } |
||
| 27 | $map[$curr]--; |
||
| 28 | } |
||
| 29 | |||
| 30 | return $prev; |
||
| 31 | } |
||
| 33 |