Find the Minimum length Unsorted Subarray , sorting which makes the complete array sorted | PHP program to find the Minimum length Unsorted Subarray , sorting which makes the complete array sorted ; step 1 ( a ) of above algo ; step 1 ( b ) of above algo ; step 2 ( a ) of above algo ; step 2 ( b ) of above algo ; step 2 ( c ) of above algo ; step 3 of above algo
< ? php function printUnsorted ( & $ arr , $ n ) { $ s = 0 ; $ e = $ n - 1 ; for ( $ s = 0 ; $ s < $ n - 1 ; $ s ++ ) { if ( $ arr [ $ s ] > $ arr [ $ s + 1 ] ) break ; } if ( $ s == $ n - 1 ) { echo " The ▁ complete ▁ array ▁ is ▁ sorted " ; return ; } for ( $ e = $ n - 1 ; $ e > 0 ; $ e -- ) { if ( $ arr [ $ e ] < $ arr [ $ e - 1 ] ) break ; } $ max = $ arr [ $ s ] ; $ min = $ arr [ $ s ] ; for ( $ i = $ s + 1 ; $ i <= $ e ; $ i ++ ) { if ( $ arr [ $ i ] > $ max ) $ max = $ arr [ $ i ] ; if ( $ arr [ $ i ] < $ min ) $ min = $ arr [ $ i ] ; } for ( $ i = 0 ; $ i < $ s ; $ i ++ ) { if ( $ arr [ $ i ] > $ min ) { $ s = $ i ; break ; } } for ( $ i = $ n - 1 ; $ i >= $ e + 1 ; $ i -- ) { if ( $ arr [ $ i ] < $ max ) { $ e = $ i ; break ; } } echo " ▁ The ▁ unsorted ▁ subarray ▁ which ▁ makes ▁ " . " the ▁ given ▁ array ▁ " . " STRNEWLINE " . " ▁ sorted ▁ lies ▁ between ▁ the ▁ indees ▁ " . $ s . " ▁ and ▁ " . $ e ; return ; } $ arr = array ( 10 , 12 , 20 , 30 , 25 , 40 , 32 , 31 , 35 , 50 , 60 ) ; $ arr_size = sizeof ( $ arr ) ; printUnsorted ( $ arr , $ arr_size ) ; ? >