Practice Most Profitable Path in a Tree
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Most Profitable Path in a Tree
Problem Statement
edges describes an undirected tree rooted at 0, and amount[i] is an even signed gate payment: negative costs money and nonnegative grants a reward. Alice starts at 0 and chooses a path to a leaf; Bob starts at bob and follows the path to 0. Each moves one edge per second and stops at their destination. Only the first arrival receives or pays the gate amount; simultaneous arrivals split it equally. Return the maximum net income Alice can achieve.
Source: Most Profitable Path in a Tree on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
edges = [[0,1],[1,2],[1,3],[3,4]], bob = 3, amount = [-2,4,2,-4,6]
6
# Example 2
edges = [[0,1]], bob = 1, amount = [-7280,2350]
-7280
Constraints
Related LeetCode Problems
Practice more problems similar to Most Profitable Path in a Tree.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.