Overheat Prevention Controller
Learn this problemProblem statement
You are implementing firmware for a multicore processor. Each core runs a configurable workload that produces heat, every core has its own active-cooling capacity, and all running cores share a pooled-cooling capacity.
The operating system changes workloads with SetCoreLoad and calls Tick to learn which cores have changed between running and shut down.
Practice Thermal Model
For this exercise, use the following deterministic model:
- At time
0, every core is running with temperature0and load0. - Time and all operation timestamps are measured in whole seconds.
- If
rcores are running during a second, each running core receivesfloor(pooledCooling / r)units of pooled cooling for that second. - For a running core
i, its temperature changes during that second byload[i] - activeCooling[i] - floor(pooledCooling / r). Temperature cannot fall below0. - If a core's temperature reaches or exceeds
shutdownTemperatureat the end of a second, it shuts down before the next second. Pooled cooling is redistributed among the remaining running cores. - A shut-down core does not heat or cool until it is restarted by
SetCoreLoad. Restarting sets its temperature to0.
Operations
The arrays operations and operationData describe calls in non-decreasing timestamp order. Operations with the same timestamp are processed in array order.
SetCoreLoadhas data[timestamp, coreId, watts]. First advance the controller totimestamp, then set that core's load towatts. If the core is shut down, restart it at temperature0.Tickhas data[timestamp]. Advance the controller totimestamp, return the IDs of all cores whose running/shut-down status changed at least once since the previousTick, sorted in ascending order, then clear the change set.
If one core changes status multiple times between two Tick calls, include its ID only once.
Return one row for every Tick, in call order. Complete simulateOverheatController with parameters pooledCooling, coreIds, activeCooling, shutdownTemperature, operations, and operationData.
Function
simulateOverheatController(pooledCooling: int, coreIds: int[], activeCooling: int[], shutdownTemperature: int, operations: String[], operationData: int[][]) → int[][]Examples
Example 1
pooledCooling = 4coreIds = [10,20]activeCooling = [1,1]shutdownTemperature = 10operations = ["SetCoreLoad","SetCoreLoad","Tick","Tick"]operationData = [[0,10,8],[0,20,4],[2],[3]]return = [[10],[]]While both cores run, each receives floor(4 / 2) = 2 pooled-cooling units. Core 10 heats by 8 - 1 - 2 = 5 per second and reaches temperature 10 at time 2, so the first Tick returns [10].
Core 20 remains running through time 3, so the second Tick returns an empty row.
Example 2
pooledCooling = 3coreIds = [1]activeCooling = [2]shutdownTemperature = 5operations = ["SetCoreLoad","Tick","SetCoreLoad","Tick","SetCoreLoad","Tick","SetCoreLoad","Tick"]operationData = [[0,1,6],[1],[1,1,0],[3],[3,1,10],[4],[4,1,4],[5]]return = [[],[],[1],[1]]The first two Tick calls observe no status change. After the load becomes 10, the core reaches the shutdown temperature at time 4, so the third row is [1].
The following SetCoreLoad restarts the core at time 4. The final Tick reports that restart as another status change.
Constraints
1 <= coreIds.length = activeCooling.length <= 200- All
coreIdsare distinct. 0 <= pooledCooling, activeCooling[i] <= 10^61 <= shutdownTemperature <= 10^91 <= operations.length = operationData.length <= 2000coreIds.length * operations.length <= 2 * 10^5- Every operation is either
SetCoreLoadorTick. - Operation timestamps are integers in
[0, 10^9]and are non-decreasing. - Every
SetCoreLoaduses a valid core ID and a load in[0, 10^6]. - There is at least one
Tickoperation.