comparing new difference with the previous one and updating accordingly
if ( $ diff > ( $ max - $ min ) ) { $ diff = $ max - $ min ; $ res_max = $ max ; $ res_mid = $ sum - ( $ max + $ min ) ; $ res_min = $ min ; } }