AlgoMaster Logo
AlgoMasterAudit Distributed Transaction Outcomesmedium

Audit Distributed Transaction Outcomes

medium

Operational reconciliation often starts by comparing the outcome recorded by every service that participated in a distributed transaction. Conflicting terminal outcomes prove a partial commit, while missing or unfinished outcomes leave the transaction in doubt.

Design a DistributedTransactionAuditor class:

  • DistributedTransactionAuditor() creates a stateless auditor.
  • String[] audit(String[] records) returns one finding for every anomalous transaction.

Each record has the exact format:

state is "COMMITTED", "ABORTED", "PENDING", or "UNKNOWN". Transaction and service ids contain no colon.

Classify each transaction independently:

  1. If it contains at least one COMMITTED and at least one ABORTED record, classify it as "PARTIAL_COMMIT". This takes precedence over unresolved states.
  2. Otherwise, if it contains at least one PENDING or UNKNOWN record, classify it as "IN_DOUBT".
  3. Otherwise, every record agrees on commit or abort. The transaction is consistent and must be omitted.

Return findings as "transactionId:classification", sorted by transaction id in ascending lexicographic order.

Example 1:

Input:

Output:

Explanation: t1 has conflicting durable outcomes, t2 is consistently committed, and t3 has not reached a known terminal result.

Example 2:

Input:

Output:

Explanation: Transaction a is a consistent abort and is omitted. The unresolved transactions are sorted by id rather than input position.

Constraints

  • 0 <= records.length <= 1000
  • Transaction and service ids contain 1 to 40 printable ASCII characters other than colon.
  • Every transaction-id and service-id pair appears at most once.
  • Every state is "COMMITTED", "ABORTED", "PENDING", or "UNKNOWN".
  • At most 100 calls are made to audit, and calls are independent.
Hints

Loading...
CallReturns
new DistributedTransactionAuditor()null
audit(["t1:orders:COMMITTED","t1:payments:ABORTED","t2:orders:COMMITTED","t2:payments:COMMITTED","t3:inventory:PENDING"])["t1:PARTIAL_COMMIT","t3:IN_DOUBT"]

t1 has conflicting terminal outcomes, t2 is consistently committed, and t3 still has an unresolved service.

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