Priyanka and Toys

  • + 0 comments

    Here is my PHP solution:

    function toys($w) {
        // Write your code here
        sort($w);
        $count_w = count($w);
        $w_first = $w[0];
        $counter = 1;
        
        for ($i=0; $i < $count_w; $i++) {
            if ($w[$i] > (4 + $w_first)) {
                $counter++;
                $w_first = $w[$i];
            }
        }  
        return $counter;
    }