• + 0 comments

    You can make the script easier if you use a native sort method. That way you just shift the array each time.

    function cutTheSticks($arr) {
        sort($arr);
        $countedValues = array_count_values($arr);
        while($countedValues) {
            $results[] = array_sum($countedValues);
            array_shift($countedValues);
        }
        return $results;
    }