Ropes left after every removal of smallest | Function print how many Ropes are Left AfterEvery Cutting operation ; sort all Ropes in increase of there length ; min length rope ; now traverse through the given Ropes in increase order of length ; After cutting if current rope length is greater than '0' that mean all ropes to it 's right side are also  greater than 0 ; now current rope become min length rope ; After first operation all ropes length become zero ; Driver Code
< ? php function cuttringRopes ( $ Ropes , $ n ) { sort ( $ Ropes ) ; $ singleOperation = 0 ; $ cuttingLenght = $ Ropes [ 0 ] ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) { if ( $ Ropes [ $ i ] - $ cuttingLenght > 0 ) { echo ( $ n - $ i ) . " ▁ " ; $ cuttingLenght = $ Ropes [ $ i ] ; $ singleOperation ++ ; } } if ( $ singleOperation == 0 ) echo "0 ▁ " ; } $ Ropes = array ( 5 , 1 , 1 , 2 , 3 , 5 ) ; $ n = count ( $ Ropes ) ; cuttringRopes ( $ Ropes , $ n ) ; ? >