Minimum steps to reach a destination | source -> source vertex step -> value of last step taken dest -> destination vertex ; base cases ; if we go on positive side ; if we go on negative side ; minimum of both cases ; Driver code
< ? php function steps ( $ source , $ step , $ dest ) { if ( abs ( $ source ) > ( $ dest ) ) return PHP_INT_MAX ; if ( $ source == $ dest ) return $ step ; $ pos = steps ( $ source + $ step + 1 , $ step + 1 , $ dest ) ; $ neg = steps ( $ source - $ step - 1 , $ step + 1 , $ dest ) ; return min ( $ pos , $ neg ) ; } $ dest = 11 ; echo " No . ▁ of ▁ steps ▁ required ▁ to ▁ reach ▁ " , $ dest , " ▁ is ▁ " , steps ( 0 , 0 , $ dest ) ; ? >