Problem · Array
Update Pod Counts From Logs
Learn this problemProblem statement
You are given the current pod counts for n microservices and a list of logs. Each log has three integers [timestamp, podIndex, value].
- If
podIndex != -1, update that 1-based pod index tovalue. - If
podIndex == -1, update every pod whose current count is less thanvaluetovalue.
The source notes that the timestamp is irrelevant for computing the final counts. Return the final pod counts after applying the logs in order.
Function
updatePodCounts(pods: int[], logs: int[][]) → int[]Examples
Example 1
pods = [1,2,3,4]logs = [[1,-1,3],[2,2,20],[1,-1,1]]return = [3,20,3,4]The first log raises pod counts below 3, giving [3,3,3,4]. The second log sets pod 2 to 20. The final global update to 1 changes nothing.