choose minimum from , 1 ) collecting coins using all vertical lines ( total r - l ) 2 ) collecting coins using lower horizontal lines and recursively on left and right segments
return min ( $ r - $ l , minStepsRecur ( $ height , $ l , $ m , $ height [ $ m ] ) + minStepsRecur ( $ height , $ m + 1 , $ r , $ height [ $ m ] ) + $ height [ $ m ] - $ h ) ; }