Minimum absolute difference of adjacent elements in a circular array | PHP program to find maximum difference between adjacent elements in a circular array . ; Checking normal adjacent elements ; Checking circular link ; Driver Code
< ? php function minAdjDifference ( $ arr , $ n ) { if ( $ n < 2 ) return ; $ res = abs ( $ arr [ 1 ] - $ arr [ 0 ] ) ; for ( $ i = 2 ; $ i < $ n ; $ i ++ ) $ res = min ( $ res , abs ( $ arr [ $ i ] - $ arr [ $ i - 1 ] ) ) ; $ res = min ( $ res , abs ( $ arr [ $ n - 1 ] - $ arr [ 0 ] ) ) ; echo " Min ▁ Difference ▁ = ▁ " , $ res ; } $ a = array ( 10 , 12 , 13 , 15 , 10 ) ; $ n = count ( $ a ) ; minAdjDifference ( $ a , $ n ) ; ? >