I came across this question in one of my challenges and i could not wrap my head around it. | SoloLearn: Learn to code for FREE!

+2

I came across this question in one of my challenges and i could not wrap my head around it.

Anyone to help how we arrive to '2' as the output https://code.sololearn.com/cgg6bldSNBVW/?ref=app

8/11/2020 6:19:40 AM

Õmari

9 Answers

New Answer

+9

sum (4,2) = 1 + sum(3,1) = 1 + (1 + sum(2,0)) # now it will hit the base case = 1 + (1 + 0) = 2

+4

True Õmmy ok...last test: Did you understand that this is an implenentation of the function min(a, b) for a, b > 0? if not it might be a good challenge to.

+2

It's recursion The function is calling itself and running like a loop untill the condition is meet

+2

Thank you all for your answers, Arsenic you made it crystal clear.

+2

Thank you Oma Falk i understand now

+1

Oma Falk That sounds better!

+1

Alexander Thiem thanks for checking.

0

Oma Falk an implementation for difference? No appearently not Input:4,1 does not result in 3......

0

Alexander Thiem typo it was min