F5 interview question

Manager gave me a algorithm question to solve-

Interview Answer

Anonymous

Aug 7, 2019

I solved it in iterative but in starting mentioned can be solved with recursion and got stuck for 15 mins and that was my mistake.