Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/23/2022 in all areas

  1. Try function getBeritsCandies(array $candies): array { $quota = floor(count($candies)/2); // Berit's share $k = array_count_values($candies); $berit = []; arsort($k); // start with ones we have most of foreach ($k as $t => &$n) { if ($n > 1 ) { // if we have multiple, Berit can can have all but 1 $m = $n - 1; // until she has her quota for ($i=0; $i<$m; $i++) { if (count($berit) == $quota) break; $berit[] = $t; --$n; } } elseif (count($berit) < $quota) { $berit[] = $t; --$n; } } return $berit; } Results Berits candies: 1, 2 Berits candies: 1, 2 Berits candies: 1, 2, 5, 3 Berits candies: 1, 1, 1, 5, 5
    1 point
This leaderboard is set to New York/GMT-05:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.