Diameter of a Tree — Solution & Editorial
Double BFS: from any node find the farthest node A; from A find the farthest distance — that is the diameter (provable by the exchange argument on tree paths).
Complexity: O(N)
Double BFS: from any node find the farthest node A; from A find the farthest distance — that is the diameter (provable by the exchange argument on tree paths).
Complexity: O(N)