HARDasked at 1 company

Maximum Good Subtree Score

A hard-tier problem at 44% community acceptance, tagged with Array, Dynamic Programming, Bit Manipulation. Reported in interviews at Infosys and 0 others.

Founder's read

Maximum Good Subtree Score is a hard problem that combines tree traversal with bitmask DP, and Infosys has reportedly asked it. You're looking at a tree structure where you need to compute subtree scores using bit operations and dynamic programming to find the optimal configuration. With a 43.6% acceptance rate, this one separates candidates who understand bitmask DP from those who treat it as a tree problem and miss the bit manipulation layer entirely. The trick isn't complex, but it's hidden under several abstractions. If you blank on it during the live assessment, StealthCoder surfaces the exact DP recurrence and bitmask pattern in seconds, invisible to the proctor.

Companies asking
1
Difficulty
HARD
Acceptance
44%

Companies that ask "Maximum Good Subtree Score"

If this hits your live OA

Maximum Good Subtree Score 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. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.

Get StealthCoder
What this means

The core challenge is recognizing that you're not just computing tree values; you're computing a state space where each subtree can be in one of multiple configurations, and those configurations map cleanly to bitmasks. The naive approach fails because it tries to compute a single score per subtree. The correct approach realizes that you need to track which bits or states are 'good' across each node, and the answer comes from a specific subtree configuration that maximizes the score. DFS + memoization on (node, bitmask) is the pattern. Common pitfall: computing the bitmask wrong or trying to merge child states without understanding the constraint that defines 'good.' Another pitfall: forgetting that the answer is the max across all possible masks at all nodes, not just the root. StealthCoder is the hedge when you hit this problem live and the problem statement doesn't immediately click into the DP shape.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Maximum Good Subtree Score recycles across companies for a reason. It's hard-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. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximum Good Subtree Score interview FAQ

What does 'good' mean in this problem?+

The problem statement defines a 'good' subtree by a specific constraint involving the bitmask or configuration of nodes within it. You'll need to read the exact definition, but it typically ties the score or structure to a boolean property that's efficiently checkable via bitmask. The score is then computed over subtrees that satisfy this constraint.

Is this really a tree DP problem or a bitmask problem?+

Both. It's tree DP where the state space is indexed by bitmasks. You traverse the tree with DFS and at each node compute the best score for each possible bitmask subset or configuration. The bitmask isn't decoration; it's the only way to encode which subtree configurations are valid.

How do you merge child subtree results?+

For each child, you already have DP values for all bitmask states at that subtree. When merging multiple children into a parent, you combine their bitmask states and recompute the constraint. The tricky part is figuring out which combined bitmask states still satisfy the 'good' property and how to update the score accordingly.

Will this problem still show up at Infosys interviews?+

Yes. Infosys has reportedly asked it and hard DP tree problems remain part of their screening rounds. A 43.6% acceptance rate means you're competing against candidates who've seen the pattern. If you haven't drilled bitmask DP on trees, this is the exact problem where a wall hit becomes a fail without external help.

What's the time complexity I should target?+

Since the state space is (node, bitmask) and bitmask can be up to 2^n for a tree of size n, the absolute worst case is exponential in tree size. However, if n is small (often 15 to 20 nodes in such problems), O(n * 2^n) or O(n^2 * 2^n) is acceptable. The real constraint is hidden in the problem; read it carefully.

Want the actual problem statement? View "Maximum Good Subtree Score" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.