Skip to content

Instantly share code, notes, and snippets.

@ItsMurumba
Last active September 14, 2017 04:39
Show Gist options
  • Select an option

  • Save ItsMurumba/27c9430c48545adebc5a17f4c07668ab to your computer and use it in GitHub Desktop.

Select an option

Save ItsMurumba/27c9430c48545adebc5a17f4c07668ab to your computer and use it in GitHub Desktop.
max_pair
<?php
function max_pair($A){
$n=sizeof($A);
//Initialize the max sum
$a=$A[0];
$b=$A[1];
for($i=0;$i<$n;$i++){
for($j=$i+1;$j<$n;$j++){
if($A[$i]+$A[$j]>$a+$b){
$a=$A[$i];
$b=$A[$j];
}
}
}
print "The pair that gives a max comnibation is:" . $a .",".$b;
}
max_pair([10, 5, 6, 3, 9]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment