Confusion between O(n) and O(n2)

What is the order of this solution as taught?
What will happen if I keep a separate height function which is called twice by each call of the isBalanced() recursive function?

The complexity of PostOrder/Bottom up approach is O(n)
The complexity of PreOrder approach where always need to call the height function is O(n^2)

Still in leetcode when I am submitting the solution, the time taken by the post order one is shown to be more than the preorder one.
Shall I send both the codes?

Don’t go by that time as shown on leetcode. Sometime the same code on resubmitting gives a better time.What you can manually observe here is that time complexity of Post Order approach is better and that is correct. The same has been taught by Prateek Bhaiya in the lecture videos.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.