Birthday Cake Candle Code

Birthday Cake Candle Code

Birthday Cake Candle Code
You are in charge of the cake for a child's birthday. You have decided the cake will have one candle for each year of their total age. They will only be able to blow out the tallest of the candles. Count how many candles are tallest.

Example=[4,4,2,1]


The maximum height  candles are 4 units high. There are 2 of them, so return 2.


// Complete the birthdayCakeCandles function below.
function birthdayCakeCandles($ar)
{
    $maxi = max($ar);
    $count = 0;
    for ($i = 0;$i < count($ar);$i++)
    {
        if ($ar[$i] == $maxi)
        {
            $count++;
        }

    }
    return $count;
}

$fptr = fopen(getenv("OUTPUT_PATH") , "w");

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%d\n", $ar_count);

fscanf($stdin, "%[^\n]", $ar_temp);

$ar = array_map('intval', preg_split('/ /', $ar_temp, -1, PREG_SPLIT_NO_EMPTY));

$result = birthdayCakeCandles($ar);

fwrite($fptr, $result . "\n");

fclose($stdin);
fclose($fptr);




0 Response to "Birthday Cake Candle Code"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel