Final Pod Counts After Logs
Problem statement
Developers are optimizing their horizontal pod autoscaler for their microservices. There are n microservices, and the number of pods for the iᵗʰ microservice is pods[i].
According to traffic patterns, the number of pods for a service can increase or decrease. Additionally, at specific times when there is expected traffic, all services with fewer than x pods are assigned x pods.
There is an event log of size m, described as a 2D array logs where logs[i] is an array of integers of size 3. The logs have the following interpretations:
[1, p, x]: The number of pods of thepᵗʰ microservice is changed tox(1 ≤ p ≤ n)[2, -1, x]: All microservices whose number of pods is less thanxare changed tox
Your task is to find the resulting number of pods for each microservice after processing all the logs.
Function
getFinalPods(pods: int[], logs: int[][]) → int[]Examples
Example 1
pods = [2, 4, 1, 4]logs = [[1, 2, 30], [1, 3, 4], [2, -1, 10]]return = [10, 30, 10, 10]n = 4
pods = [2, 4, 1, 4]
m = 3
logs = [[1, 2, 30], [1, 3, 4], [2, -1, 10]]
| Current Number of Pods | Log | Resulting Pods |
|---|---|---|
[2, 4, 1, 4] | [1, 2, 30] 2nd member’s pod count is changed to 30. | [2, 30, 1, 4] |