Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly for of the five integers. Then print the respective minimum and maximum values.
$arr = array(1,4,2,8,4,0);

$temp_arr = array(); 
foreach($arr as $index => $row){
    $temp_arr[] = array_sum($arr) - $arr[$index]; 
}

sort($temp_arr);
echo "Minimum number is ->" .$temp_arr[0] ."\n"; 
echo "Maximum number is ->" .$temp_arr[count($temp_arr)-1];

Output:

Question reference: Hacker rank

Leave a Reply

Your email address will not be published. Required fields are marked *