Problem · Array

Final Pod Counts After Logs

MediumSalesforceOA
See Salesforce hiring insights

Developers are optimizing their horizontal pod autoscaler for their microservices. There are n microservices, and the number of pods for the ith 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 the pth microservice is changed to x (1 <= p <= n).
  • [2, -1, x]: All microservices whose number of pods is less than x are changed to x.

Your task is to find the resulting number of pods for each microservice after processing all the logs.

Examples
01 · Example 1
pods = [2, 4, 1, 4]
logs = [[1, 2, 30], [1, 3, 4], [2, -1, 10]]
return = [10, 30, 10, 10]

Processing the logs:

  1. For [1, 2, 30], the 2nd microservice's pod count is changed to 30, so the pods become [2, 30, 1, 4].
  2. For [1, 3, 4], the 3rd microservice's pod count is changed to 4, so the pods become [2, 30, 4, 4].
  3. For [2, -1, 10], all microservices with fewer than 10 pods are changed to 10, so the pods become [10, 30, 10, 10].

Therefore, the answer is [10, 30, 10, 10].

Source note (June 28, 2026): The original post did not include the output for this example. FastPrep worked it out from the problem statement and the given input. If you have the original output or notice something wrong, please let us know and we'll fix it. If we find the original source later, we'll come back and update this too. 🐿️

More Salesforce problems
drafts saved locally
public int[] getFinalPods(int[] pods, int[][] logs) {
  // write your code here
}
pods[2, 4, 1, 4]
logs[[1, 2, 30], [1, 3, 4], [2, -1, 10]]
expected[10, 30, 10, 10]
checking account