FastPrepFinal Pod Counts After Logs

Final Pod Counts After Logs

Salesforce logoSalesforce● MediumFULLTIMEOA
Learn

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 the pᵗʰ 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.

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 PodsLogResulting Pods
[2, 4, 1, 4][1, 2, 30] 2nd member’s pod count is changed to 30.[2, 30, 1, 4]

More Salesforce problems

See Salesforce hiring insights
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…