All practice tasks

Coding (Algo)

Synchronize Repeating Cycles

Number theory · Medium

A scheduler combines periodic maintenance cycles expressed in whole ticks. It needs the first shared period, not a simulation of every tick. A disabled cycle is represented by zero and makes the combined period zero.

Return the least common multiple of cycle magnitudes with exact integer arithmetic.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

{ nums: integer[] }

Fields

  • nums is an array of signed integers in its original order. Equal values at different indexes are separate entries.

Output

Return value

  • Empty input returns 1. Any zero returns 0. Otherwise return the smallest positive shared multiple.
  • Signs do not change the period. Do not return an approximation.

Constraints

  • 0 <= nums.length <= 100000; -1000000000 <= nums[i] <= 1000000000.
  • All requested totals and counts fit exactly in a safe JSON integer.
  • The mathematical LCM is at most 9007199254740991. Use exact intermediate arithmetic; intermediate products before division may exceed that.

Examples

Example 1

{
  "nums": [
    6,
    -8
  ]
}

Returns

24

Example 2

{
  "nums": [
    6,
    0,
    8
  ]
}

Returns

0

Required complexity

O(n log M) greatest-divisor steps with exact integer intermediates and O(1) accumulators

What this task practices

Synchronize Repeating Cycles is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as medium difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.