Horizontal Pod Autoscaler
Updated
Problem statement
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 thepth microservice is changed tox(1 <= p <= n).[2, -1, x]: All microservices whose number of pods is less thanxare changed tox.
Find the resulting number of pods for each microservice after processing all the logs.
Function
findPodCount(pods: int[], logs: int[][]) → int[] Complete the function findPodCount in the editor below.
findPodCount has the following parameters:
int pods[n]: the number of pods for the microservicesint logs[m][3]: the event log of the horizontal pod autoscaler
Returns int[n]: the ith element represents the final pod count of the ith microservice
Examples
Example 1
pods = [2, 4, 1, 4]logs = [[1, 2, 30], [1, 3, 4], [2, -1, 10]]return = [10, 30, 10, 10]| Current Number of Pods | Log | Resulting Pods |
|---|---|---|
[2, 4, 1, 4] |
2nd member's pod count is changed to | [2, 30, 1, 4] |
[2, 30, 1, 4] |
3rd member's pod count is changed to | [2, 30, 4, 4] |
[2, 30, 4, 4] |
All the microservices with fewer than | [10, 30, 10, 10] |
The final number of pods is [10, 30, 10, 10].
Example 2
pods = [3, 50, 2, 1, 10]logs = [[1, 2, 0], [2, -1, 8], [1, 3, 20]]return = [8, 8, 20, 8, 10]Apply the logs in order: a type-one log sets one service to the given pod count, and a type-two log raises every service below the given value up to that value.
Constraints
1 <= n <= 2 * 10^51 <= pods[i] <= 10^91 <= m <= 2 * 10^51 <= p <= n0 <= x <= 10^9
More Snowflake interview questions
- Connect Four from the Last MovePHONE SCREEN · Seen Nov 2026
- Minimum Edits to a Perfect Binary TreePHONE SCREEN · Seen Nov 2026
- Parallel Courses IIIONSITE INTERVIEW · Seen Nov 2026
- Safest Shortest Path Through a GridOA · Seen Nov 2026
- Configurable Per-Client Token BucketsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Find Valid SET Card TriplesOA · PHONE SCREEN · Seen Nov 2026
- LFU CacheOA · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Index Distance Between Person and CakeOA · PHONE SCREEN · Seen Nov 2026
- Minimum N-ary Tree Depth DeletionsOA · PHONE SCREEN · Seen Nov 2026
- Sum of Binary Tree Boundary NodesOA · PHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Photo AlbumHonda R&D · OA
- Rolling MetricsAkuna Capital · OAAkuna Capital interview questions
- Minimum Bridge TurnbacksBNSF Railway · OABNSF Railway interview questions
- Count Smaller Prior ElementsTata Consultancy Services · OATata Consultancy Services interview questions
- Horizontal Pod AutoscalerRubrik · OARubrik interview questions
- Adjust Prices 🍱DoorDash · OADoorDash interview questions
- Photo AlbumFactSet · OAFactSet interview questions
- Maximum Profit from an Increasing Price TripletOdoo · OAOdoo interview questions
- Count Decreasing TripletsAirbnb · OAAirbnb interview questions
- Maximize Shipment Order by Sorting One WindowAmazon · OA