AlgoMaster Logo
AlgoMasterClassify Retry Outcomeseasy

Classify Retry Outcomes

easy

A broker retries messages that fail because some failures are temporary. Once a message exceeds the retry budget, continuing to retry it can block useful work and overload an unhealthy dependency. The broker moves that message to a dead-letter queue (DLQ) for inspection or later replay.

Design a DeadLetterRouter class:

  • DeadLetterRouter() creates a stateless router.
  • String[] classify(int[] failures, int maxRetries) returns the final disposition of every message.

failures[i] is the number of times message i failed before it either succeeded or exhausted the configured policy:

  • Return "delivered" when failures[i] <= maxRetries.
  • Return "dlq" when failures[i] > maxRetries.

Preserve the input order. Each call is independent, and the input array must not be mutated.

Example 1:

Input:

Output:

Explanation: The messages with 0, 2, and 1 failures stay within the two-retry budget. The messages with 3 and 4 failures exceed it and are routed to the DLQ.

Example 2:

Input:

Output:

Explanation: With no retries configured, a message that has zero failures is still delivered because its initial processing attempt succeeds.

Constraints

  • 0 <= failures.length <= 10^5
  • 0 <= failures[i] <= 10^9
  • 0 <= maxRetries <= 10^9
  • Return exactly one disposition for each message.
  • At most 100 calls are made to classify.
Hints

Loading...
CallReturns
new DeadLetterRouter()null
classify([0,2,3,1,4], 2)["delivered","delivered","dlq","delivered","dlq"]

Counts 0, 2, and 1 remain within the two-retry budget. Counts 3 and 4 exceed it and are routed to the DLQ.

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