A team offsite planner wants the most enthusiastic guest list. The reporting structure is a binary tree, and each node's value is that person's enthusiasm score. To keep things relaxed, nobody may be invited together with their direct manager (their parent in the tree).
Write bestInviteScore(root) that returns the largest total score of a guest list where no invited person is the direct parent of another invited person. An empty tree returns 0.
Input: root = [3,2,3,null,3,null,1] Output: 7
Invite the root 3, plus the 3 and 1 on the bottom row: 3 + 3 + 1 = 7.
Input: root = [3,4,5,1,3,null,1] Output: 9
Invite 4 and 5, the root's two reports: 4 + 5 = 9.
0 <= number of people <= 10^40 <= score <= 10^4Trees are written level by level, like [1, 2, 3, null, 4], where null is a missing child. Your function works with TreeNode objects, each with val, left, and right.
Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #349 Invite List Without Direct Managers. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.