Will the time complexity of this solution be O(n), as we are calculating the sum again and again for the same subtree. For eg. if I am at root node ill be calculating the sum of the entire tree, then again for the left subtree ill call for the same left subtree of that left subtree. So the time complexity would be O(n^2).
Time Complexity of the solution in video
The approach used in the video is O(n^2). You are correct.
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.