Select transactions to maximize fees under size
Problem: Max-Fee Block Assembly
You are tasked with selecting a subset of transactions to include in a block, aiming to maximize the total fees collected while adhering to a block's maximum capacity.
Each transaction is defined by:
id: A unique identifier.size: A positive integer representing the transaction's size.fee: A non-negative integer representing the fee associated with the transaction.
A block has a maximum total capacity B.
Objective
Choose a subset of N given transactions such that:
- The sum of
sizefor all chosen transactions is less than or equal toB. - The sum of
feefor all chosen transactions is maximized.
Input
Ntransactions: Provided as a list of(id, size, fee)tuples.B: The maximum block capacity.
Output
The maximum achievable total fee, and/or the list of IDs of the chosen transactions.
Constraints
1 <= N <= 20001 <= B <= 1001 <= size <= Bfor any transaction.0 <= fee <= 10^9for any transaction.
Follow-up: Parent/Child Dependencies
Now, each transaction may optionally include a parent_id. If a transaction is selected for inclusion in the block, all of its ancestors (parents, grandparents, etc.) must also be included. Assume that dependencies form a forest (i.e., no cycles, and a transaction can have at most one parent, forming tree-like structures).
Objective for Follow-up
Choose a valid subset of transactions that respects the parent/child dependencies and the block capacity B, while maximizing the total fee.
Clarification
If multiple optimal subsets exist (yielding the same maximum fee), any one of them is considered a valid solution.
AI interview prep
Core dilemma
The central engineering conflict is adapting the classic 0/1 Knapsack problem to efficiently handle a large number of items (N) with a small capacity (B), and then extending this solution to incorporate complex, tree-like parent-child dependencies while maintaining optimality.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Select transactions to maximize fees under size
Problem: Max-Fee Block Assembly
You are tasked with selecting a subset of transactions to include in a block, aiming to maximize the total fees collected while adhering to a block's maximum capacity.
Each transaction is defined by:
id: A unique identifier.size: A positive integer representing the transaction's size.fee: A non-negative integer representing the fee associated with the transaction.
A block has a maximum total capacity B.
Objective
Choose a subset of N given transactions such that:
- The sum of
sizefor all chosen transactions is less than or equal toB. - The sum of
feefor all chosen transactions is maximized.
Input
Ntransactions: Provided as a list of(id, size, fee)tuples.B: The maximum block capacity.
Output
The maximum achievable total fee, and/or the list of IDs of the chosen transactions.
Constraints
1 <= N <= 20001 <= B <= 1001 <= size <= Bfor any transaction.0 <= fee <= 10^9for any transaction.
Follow-up: Parent/Child Dependencies
Now, each transaction may optionally include a parent_id. If a transaction is selected for inclusion in the block, all of its ancestors (parents, grandparents, etc.) must also be included. Assume that dependencies form a forest (i.e., no cycles, and a transaction can have at most one parent, forming tree-like structures).
Objective for Follow-up
Choose a valid subset of transactions that respects the parent/child dependencies and the block capacity B, while maximizing the total fee.
Clarification
If multiple optimal subsets exist (yielding the same maximum fee), any one of them is considered a valid solution.