Binary Tree Diameter Time : O(n) Space : O(d) 123456789101112131415161718192021222324252627282930using namespace std;// This is an input class. Do not edit.class BinaryTree {public: int value; BinaryTree *left; BinaryTree *right; BinaryTree(int value) { this->value = value; left = nullptr; right = nullptr; }};int helper(BinaryTree *node, int& res) { if(!node) return 0; int ldepth = helper(node->left, res); int rdepth = helper(node->right, res); res = max(res, ldepth + rdepth); return max(ldepth, rdepth) + 1;}int binaryTreeDiameter(BinaryTree *tree) { int res = -1; helper(tree, res); return res;}