Problem · String

Service Pipeline Stabilization Time

Learn this problem
MediumAmazonOA
See Amazon hiring insights

Problem 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) → int

Examples

Example 1

pipeline = "database"failedService = "a"return = 2

n = 8, pipeline = "database", and failedService = 'a'.

Here is how the system stabilizes over time:

  1. Initial state, time = 0:

    • pipeline = "database"
    • The failedService 'a' is at indices 1, 3, and 5 using 0-based indexing.
  2. At time = 1:

    • The services that will be terminated in the current pipeline are as follows:
      • 'a' at index 1 removes index 0.
      • 'a' at index 3 removes index 2.
      • 'a' at index 5 removes index 4.
    • Thus, the removed characters are d, t, and b. The string pipeline becomes "aaase".
  3. At time = 2, pipeline = "aaase", and the failedService 'a' is at indices 0, 1, and 2 using 0-based indexing.

    • The 'a' at index 1 removes index 0.
    • The 'a' at index 2 removes index 1.
    • The pipeline becomes "ase".

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

drafts saved locally
public int getStabilizationTime(String pipeline, String failedService) {
  // write your code here
}
pipeline"database"
failedService"a"
expected2
checking account