Minimize ( max ( A [ i ] , B [ j ] , C [ k ] ) | PHP code for above approach ; calculating min difference from last index of lists ; checking condition ; calculating max term from list ; Moving to smaller value in the array with maximum out of three . ; Driver code
< ? php function solve ( $ A , $ B , $ C , $ i , $ j , $ k ) { $ min_diff ; $ current_diff ; $ max_term ; $ min_diff = abs ( max ( $ A [ $ i ] , max ( $ B [ $ j ] , $ C [ $ k ] ) ) - min ( $ A [ $ i ] , min ( $ B [ $ j ] , $ C [ $ k ] ) ) ) ; while ( $ i != -1 && $ j != -1 && $ k != -1 ) { $ current_diff = abs ( max ( $ A [ $ i ] , max ( $ B [ $ j ] , $ C [ $ k ] ) ) - min ( $ A [ $ i ] , min ( $ B [ $ j ] , $ C [ $ k ] ) ) ) ; if ( $ current_diff < $ min_diff ) $ min_diff = $ current_diff ; $ max_term = max ( $ A [ $ i ] , max ( $ B [ $ j ] , $ C [ $ k ] ) ) ; if ( $ A [ $ i ] == $ max_term ) $ i -= 1 ; else if ( $ B [ $ j ] == $ max_term ) $ j -= 1 ; else $ k -= 1 ; } return $ min_diff ; } $ D = array ( 5 , 8 , 10 , 15 ) ; $ E = array ( 6 , 9 , 15 , 78 , 89 ) ; $ F = array ( 2 , 3 , 6 , 6 , 8 , 8 , 10 ) ; $ nD = sizeof ( $ D ) ; $ nE = sizeof ( $ E ) ; $ nF = sizeof ( $ F ) ; echo solve ( $ D , $ E , $ F , $ nD - 1 , $ nE - 1 , $ nF - 1 ) ; ? >