Output Mismatch

8 9 7 8 -1 -1 -1 -1 -1 -1 -1
Using the O(N^2) method …Diameter comes out to be 3
Using the O(N) method …Diameter comes out to be 4

hello @ANIKET_DALAL
answer should be same using both the approaches.
if input u have mentioned is in level order.
then 3 is correct answer. check ur O(n) method there might be some implementation mistake.

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.