educative.io

Educative

Recursive vs iterative

the recursive version gives the inverse of the iterative version. Which one is correct?

Both solutions are correct since the order of the ancestors does not matter in this problem. But the complexity of the recursive solution is O(n), and the complexity of the iterative solution is O(log(n). That’s why an iterative solution is better than the recursive solution.

Maida Ijaz | Developer Advocate
educative.io

but solution window in the challange does not accept both ways