AlgoMaster Logo
AlgoMasterAudit Failure Domainsmedium

Audit Failure Domains

medium

A service can have several replicas and still contain a single point of failure when all replicas share one failure domain. In this exercise, a failure domain is an availability zone.

Design a FailureDomainAuditor class:

  • FailureDomainAuditor() creates a stateless auditor.
  • String[] atRiskComponents(String[] components, String[] zones) returns components that occupy fewer than two distinct zones.
  • String[] unavailableAfter(String[] components, String[] zones, String failedZone) returns components that have no surviving replica after failedZone fails.

The arrays are aligned: components[i] identifies a component replica and zones[i] gives that replica's zone. A component may appear multiple times.

Two replicas in the same zone still share a zone-level failure. A component is unavailable after a zone failure only when every one of its replicas is in the failed zone. Return each component at most once and sort results alphabetically. Each method call is independent.

Example 1:

Input:

Output:

Explanation: API spans two zones. Database has two replicas but both share us-east-1a; cache has one replica in us-east-1c. Both are at risk, but losing us-east-1a takes down only database.

Example 2:

Input:

Output:

Explanation: Both components span two zones and retain one replica outside zone-b.

Constraints

  • 1 <= components.length == zones.length <= 500
  • Component and zone names are non-empty lowercase strings.
  • Every array entry describes one replica.
  • failedZone is a non-empty lowercase string and need not appear in zones.
  • Return component names in ascending alphabetical order without duplicates.
  • At most 100 total method calls are made.
Hints

Loading...
CallReturns
new FailureDomainAuditor()null
atRiskComponents(["api","api","db","db","cache"], ["us-east-1a","us-east-1b","us-east-1a","us-east-1a","us-east-1c"])["cache","db"]
unavailableAfter(["api","api","db","db","cache"], ["us-east-1a","us-east-1b","us-east-1a","us-east-1a","us-east-1c"], "us-east-1a")["db"]

API spans two zones. Both database replicas share us-east-1a, while cache has only one replica in us-east-1c, so cache and database are at risk. Losing us-east-1a takes down only database.

Run checks these cases. Submit also runs a larger hidden set.