in the longest path problem i feel it can be solved by bfs…why do i need to use dp here?
Cant i use a bfs algo to know the longest path?
hello @neha_153
there is no need of dp.
u can run a dfs to find the diameter (longest path).
logic is pick two child nodes who r having highest depth.
and then calculate l1 + l2 +2 ,then compare with ur answer and update it.
and then return 1 + max(l1,l2) to its parent.