Shared Even Maintenance Cycle
Preview mode. Log in to edit, run, submit, and save progress.
Shared Even Maintenance Cycle
A maintenance coordinator needs a single positive cycle length that aligns with every machine's cycle. The chosen cycle must also be even. If the smallest valid cycle length is too large to store safely, the scheduler rejects it. Specifically, if the required value exceeds 10^18, the answer must be -1. Input Format: You are given an integer array cycles. Output Format: Return the smallest positive even cycle length divisible by every cycle value, or -1 if it exceeds the safe limit.
Examples
cycles = [5]
10
Explanation: The least common multiple of [5] is 5. Since the shared cycle must be even, the final cycle is 10.
Approach hint
Look for the state that actually matters after each operation.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.