The diameter of a binary tree is the length of the longest path between any two leaf nodes in a tree. Find diameter of Binary tree in Time Complexity O(n)
Example:
Input: Binary tree is given as an input, Time Complexity : O(n), since we must visit each node, Space Complexity O(log n), if a balanced tree, O(n) otherwise. Space complexity is due to recursion
8
Problem level: Medium