Two-phase commit coordinates one transaction across multiple participants. During the prepare phase, each participant reports whether it is ready to commit. The coordinator may commit only after every participant has voted "yes".
Design a TwoPhaseCommitCoordinator class:
TwoPhaseCommitCoordinator() creates a stateless coordinator.String decide(String[] votes) returns the final decision for one prepare phase.Each entry in votes is one of:
"yes": the participant prepared successfully."no": the participant cannot commit."timeout": the participant did not return a vote.Return "commit" only when every vote is "yes". Return "abort" when any participant votes "no" or times out. A timeout is not a negative vote from the participant, but the coordinator still cannot safely commit without its explicit agreement.
Input:
Output:
Explanation: All three participants voted yes, so the unanimous commit rule is satisfied.
Input:
Output:
Explanation: The coordinator never received explicit agreement from the second participant, so committing would be unsafe.
1 <= votes.length <= 100votes[i] is "yes", "no", or "timeout"."commit" or "abort" in lowercase.100 calls are made to decide per object.| Call | Returns |
|---|---|
| new TwoPhaseCommitCoordinator() | null |
| decide(["yes","yes","yes"]) | "commit" |
Every participant prepared successfully, so the coordinator can commit.
Run checks these cases. Submit also runs a larger hidden set.

