Problem · Array

Update Pod Counts From Logs

Learn this problem
HardSalesforceOA
See Salesforce hiring insights

Problem 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 to value.
  • If podIndex == -1, update every pod whose current count is less than value to value.

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.

More Salesforce problems

drafts saved locally
public int[] updatePodCounts(int[] pods, int[][] logs) {
  // write your code here
}
pods[1,2,3,4]
logs[[1,-1,3],[2,2,20],[1,-1,1]]
expected[3,20,3,4]
checking account