• + 0 comments

    php solution

    function migratoryBirds($arr) {
        $typesCount = [];
    
        foreach ($arr as $type) {
            if (!isset($typesCount[$type])) {
                $typesCount[$type] = 1;
            } else {
                $typesCount[$type]++;
            }
        }
    
        $maxAmount = max($typesCount);
    
        $typesWithMaxAmount = array_filter($typesCount, fn ($amount) => $amount === $maxAmount);
    
        $keys = array_keys($typesWithMaxAmount);
    
        return min($keys);
    }