code 1: https://ide.codingblocks.com/s/445899
code 2: https://ide.codingblocks.com/s/445903
problem: diameter of binary tree
is code 2 better in terms of time complexity as compared to code 1.
code 1: https://ide.codingblocks.com/s/445899
code 2: https://ide.codingblocks.com/s/445903
problem: diameter of binary tree
is code 2 better in terms of time complexity as compared to code 1.
hello @raghav007
time complexity wise both are same.
both are O(N).
but yeah code 2 is little bit efficient becuase here u r only returning height whereas in code 1 u are returning dia as well as height so it consume some extra time
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.