Two questions:
Question 1: Waste Reduction
A pharmaceutical company business scenario. The company prepares liquid medication for different patients, and the amount each patient needs varies. The medication has to be packaged into containers, and each "container set" offers bottles of different capacities.
Given: the requirement amounts for multiple patients (requirements); and several container sets, each containing a number of container capacities.
Every order must use one container, and the container must be filled completely. If there is a container capacity that exactly equals the requirement, use it directly. If there's no exact match, use the smallest container that is greater than or equal to the requirement. Container capacity minus requirement equals waste. If a set cannot satisfy a given order (no container in it is greater than or equal to the requirement), that whole set is eliminated.
Task: compute the total waste for every container set.
- Return the index (0-based) of the set with the smallest total waste.
- If multiple sets tie for the smallest total waste, return the smallest index.
- If no set can satisfy all the requirements, return -1.
Question 2: Chain of Command
An organizational structure that can be represented as a tree. There are n people total, and each person is a node in the tree. Every person except the root has exactly one superior (parent), and each person can have 0 or more direct subordinates (children). The input is a parent[] array (1-indexed): parent[i] = -1 means that person is the root (the company's top leader); every other node stores the number of its superior.
Instruction propagation rule: when someone issues an instruction, it gets passed down to all of their subordinates (including every descendant), and the propagation order is very strict — instructions go out in ascending order of child node number. For a node with multiple children, the instruction is fully propagated through the first child's entire subtree before moving on to the next child, and each child continues to propagate downward following the same rule. The instruction keeps propagating until everyone in the subtree has received it.
Task: find out who is the k-th person to receive the instruction among all the subordinates during this propagation.
Discussion
Loading comments…