Skip to content

Practice Maximum Profit from Trading Stocks with Discounts

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#3562
LeetCode Problem

Maximum Profit from Trading Stocks with Discounts

Problem Statement

A company has employees 1 through n, with employee 1 as CEO and hierarchy edges [boss, employee]. present[i] is employee i’s stock purchase price today, and future[i] is its sale price tomorrow. If an employee’s direct boss buys their own stock, that employee’s purchase price becomes floor(present[i] / 2). Each stock may be bought at most once. All purchases must be paid from the initial budget; future proceeds cannot fund purchases. Return the largest total sale proceeds minus purchase costs achievable without exceeding budget.

Source: Maximum Profit from Trading Stocks with Discounts on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 2, present = [1,2], future = [4,3], hierarchy = [[1,2]], budget = 3
Output
5

# Example 2

Input
n = 2, present = [3,4], future = [5,8], hierarchy = [[1,2]], budget = 4
Output
4

# Example 3

Input
n = 3, present = [4,6,8], future = [7,9,11], hierarchy = [[1,2],[1,3]], budget = 10
Output
10

# Example 4

Input
n = 3, present = [5,2,3], future = [8,5,6], hierarchy = [[1,2],[2,3]], budget = 7
Output
12

Constraints

1 <= n <= 160
present.length, future.length == n
1 <= present[i], future[i] <= 50
hierarchy.length == n - 1
hierarchy[i] == [ui, vi]
1 <= ui, vi <= n
ui != vi
1 <= budget <= 160
There are no duplicate edges.
Employee 1 is the direct or indirect boss of every employee.
The input graph hierarchy is guaranteed to have no cycles.

Related LeetCode Problems

Practice more problems similar to Maximum Profit from Trading Stocks with Discounts.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.