Maximize the Number of Target Nodes After Connecting Trees I
A medium-tier problem at 70% community acceptance, tagged with Tree, Depth-First Search, Breadth-First Search. Reported in interviews at jio and 0 others.
You're connecting two separate trees and need to figure out how many nodes hit a target value when you're done. The trick isn't obvious if you've mainly studied binary trees. Companies like jio have asked this. The problem sits at the boundary between tree traversal and graph connectivity. Most candidates blank on the order of operations: you need to explore both trees, find the connection point, then count targets in the merged structure. That's where the pattern lives. If you hit this during an OA and the obvious DFS doesn't work, StealthCoder runs invisibly and surfaces the right approach in seconds.
Companies that ask "Maximize the Number of Target Nodes After Connecting Trees I"
Maximize the Number of Target Nodes After Connecting Trees I is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too.
Get StealthCoderThe problem requires you to connect two trees and maximize the count of reachable target nodes. The core insight is that you're not just traversing one tree; you're merging two separate components and then doing a full traversal of the connected graph. Most candidates attempt a greedy or single-pass approach and hit a wall because they're not accounting for the connectivity change. The actual solution involves understanding how the connection point affects reachability, then running a complete DFS or BFS from all possible starting positions to find the maximum. You need to explore both trees independently, understand their structure around the target nodes, and then reason about what happens when they're connected. If you haven't seen the pattern before, it's easy to confuse this with a simpler tree DP problem. StealthCoder hedges that risk on the live assessment by reading the problem and delivering a working solution even if you blank on the connection logic.
Pattern tags
You know the problem.
Make sure you actually pass it.
Maximize the Number of Target Nodes After Connecting Trees I recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximize the Number of Target Nodes After Connecting Trees I interview FAQ
Is this just a standard tree DFS problem?+
No. It's tree DFS plus graph connectivity logic. You need to traverse both trees, identify how they connect, and then determine which nodes become reachable after the merge. Single-pass traversal won't work. You're essentially solving two subproblems: understanding each tree's target layout, then merging them optimally.
What's the main trick most candidates miss?+
Forgetting that the connection point matters. You can't just count targets in each tree separately. After you connect, some nodes that were unreachable become reachable, and vice versa depending on which node you start from. You need to simulate the merge and re-traverse.
Does acceptance rate matter for this one?+
The 69.7% acceptance rate is solid for Medium, suggesting it's not a trick problem, but it has a real conceptual barrier. Most who solve it understand the merging step. Those who don't abandon the approach entirely.
How does BFS vs DFS play into this?+
Either works for traversal. The real work is setup: building the tree structures, finding valid connection points, and then doing a full reachability pass from the merged graph. The choice between DFS and BFS doesn't change the logic, only the implementation style.
Will prepping tree DP help me here?+
Partially. Tree DP teaches you how to compute things bottom-up on a single tree. This problem needs that, but also needs you to think about graph merging and reachability after the merge. It's a slight step beyond classic tree DP.
Want the actual problem statement? View "Maximize the Number of Target Nodes After Connecting Trees I" on LeetCode →