Service Pipeline Stabilization Time
Learn this problemProblem statement
Amazon operates a massive distributed system that handles millions of requests per second across services like Prime Video, Alexa, and AWS.
Each request flows through a chain of servers represented as nodes in a pipeline. These nodes are categorized by the type of service they handle, e.g., authentication, video streaming, storage, where the i-th node is represented by the string element pipeline[i].
Due to a critical service outage caused by a bug, one specific category of service, represented by the character failedService, begins to disrupt operations. Every second, all instances of the failedService terminate the service node immediately preceding them in the pipeline to isolate the issue. Terminated services are then removed from the pipeline.
Your task is to determine how long it will take for the system to stabilize, i.e., when no further disruptions occur.
Function
getStabilizationTime(pipeline: String, failedService: String) → intExamples
Example 1
pipeline = "database"failedService = "a"return = 2n = 8, pipeline = "database", and failedService = 'a'.
Here is how the system stabilizes over time:
Initial state,
time = 0:pipeline = "database"- The
failedService 'a'is at indices1,3, and5using 0-based indexing.
At
time = 1:- The services that will be terminated in the current pipeline are as follows:
'a'at index1removes index0.'a'at index3removes index2.'a'at index5removes index4.
- Thus, the removed characters are
d,t, andb. The stringpipelinebecomes"aaase".
- The services that will be terminated in the current pipeline are as follows:
At
time = 2,pipeline = "aaase", and thefailedService 'a'is at indices0,1, and2using 0-based indexing.- The
'a'at index1removes index0. - The
'a'at index2removes index1. - The pipeline becomes
"ase".
- The
After time = 2, the remaining failedService is at the beginning of the pipeline, so no further disruptions occur.
This output was added by FastPrep to make the problem uploadable because the official source image does not show the final answer. Based on the visible stabilization process, the inferred output is 2. If you know the official output, feel free to let us know. Many thanks in advance! And we will update it once an official source is available. Thank you! 🙏 (06-23-2026 :)
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026