A rolling deployment replaces old instances gradually while preserving two fleet-wide limits.
Design a RollingDeploymentAuditor:
RollingDeploymentAuditor(int desiredReplicas, int maxSurge, int maxUnavailable) stores the rollout limits.int firstViolation(String[] events) returns the zero-based index of the first invalid event, or -1 when the complete trace is valid.boolean isComplete(String[] events) returns true only when the trace is valid and finishes with every old instance replaced.
The initial state contains desiredReplicas running old instances and no new instances. Process these events:
"START_NEW" adds one starting new instance. Total old, starting, and ready-new instances must not exceed desiredReplicas + maxSurge."READY_NEW" moves one starting instance to ready. At least one starting instance must exist."FAIL_NEW" removes one starting instance. At least one starting instance must exist."STOP_OLD" removes one running old instance. One must exist, and afterward oldRunning + newReady must be at least desiredReplicas - maxUnavailable.
Starting instances do not count as available. Any unknown event is a violation. A valid partial trace has no violation but is not complete. Each method simulates the trace independently.
Example 1:
Input:
Output:
Explanation: Every new instance becomes ready before an old instance stops. Availability stays at three and the fleet never exceeds four instances.
Example 2:
Input:
Output:
Explanation: The first start uses the single surge slot. The second would raise total fleet size to five, above the allowed four.
Constraints
1 <= desiredReplicas <= 10^40 <= maxSurge, maxUnavailable <= desiredReplicas0 <= events.length <= 10^5- Events are case-sensitive strings.
- At most
100 total method calls are made.