At 12:25, bhaiya said iterative approach takes O(n) time and O(1) space and it is better. But I think iterative approach will take O(n^2) time and O(n) space. The optimised approach in which we donot iterate will take O(n) time and O(n) space. So optimised approach is better.
Doubt at 12:25. How can iterative approach be more efficient?
@girishgargcool hey iterative approach also take O(n) time as we are just traversing the linked list one time and rest pointer connection is just of constant time so overall time complexity is O(n), now in recursion we use O(n) space whereas in iterative approach no extra space is used ,hence it is more efficient. Hope you get it.
Oh sorry! I thought by iterative method he meant the non-optimised recursive method. I have got it now. Thanks
@girishgargcool no probelm bro please close this doubt and give rating if you are satisfied with response.