Maximum possible intersection by moving centers of line segments | Function to print the maximum intersection ; Case 1 ; Case 2 ; Case 3 ; Driver Code
< ? php function max_intersection ( $ center , $ length , $ k ) { sort ( $ center ) ; if ( $ center [ 2 ] - $ center [ 0 ] >= 2 * $ k + $ length ) { return 0 ; } else if ( $ center [ 2 ] - $ center [ 0 ] >= 2 * $ k ) { return ( 2 * $ k - ( $ center [ 2 ] - $ center [ 0 ] - $ length ) ) ; } else return $ length ; } $ center = array ( 1 , 2 , 3 ) ; $ L = 1 ; $ K = 1 ; echo max_intersection ( $ center , $ L , $ K ) ; ? >