C++ Code - leetcode.com/problems/maximize-the-number-of-target-nodes-after-connecting-trees-ii/submissions/1467126572/ Please do share with your friends or social media, it will be super super helpful 🥺
Liked your approach which is definitely more intuitive, here's my approach which i felt a bit simpler. - use BFS similar to Q3, but this time instead of pre-computing count of neighboring nodes
there was one more key observation to this problem which made it trivial: if for some node "node" its even count and odd count are (x, y); then for its neighbours the even and odd count will be (y, x). They just get inverted. We then just have to find maximum such odd from Tree2 and add that to an even[i] from tree1 to get the answer (for some i)
C++ Code - leetcode.com/problems/maximize-the-number-of-target-nodes-after-connecting-trees-ii/submissions/1467126572/
Please do share with your friends or social media, it will be super super helpful 🥺
Liked your approach which is definitely more intuitive, here's my approach which i felt a bit simpler.
- use BFS similar to Q3, but this time instead of pre-computing count of neighboring nodes
Really liked the approach
there was one more key observation to this problem which made it trivial: if for some node "node" its even count and odd count are (x, y); then for its neighbours the even and odd count will be (y, x). They just get inverted. We then just have to find maximum such odd from Tree2 and add that to an even[i] from tree1 to get the answer (for some i)
made the logic and explanation TOO MUCH COMPLICATED, cant understand anything after a point