FastPrepPeriodic Event Loop
Problems/Periodic Event Loop

Periodic Event Loop

Etched logoEtched● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: An Etched software-engineer interview report posted June 20, 2026 describes a May interview with a periodic event loop whose events can be registered at any time and whose execution callback decides whether to continue. This batch interface fixes registration at time zero and represents callback continuation with run limits while preserving scheduling behavior.

At time zero, register periodic events. Event i first executes at periods[i] and should execute at each multiple of that period until it has run runLimits[i] times. A run limit models a callback returning false after that execution.

Execute only events due at or before horizon. When several events are due together, run smaller eventIds first. Return an execution log of strings time:eventId. Event IDs are unique.

Function

runPeriodicEvents(eventIds: String[], periods: int[], runLimits: int[], horizon: int) → String[]

Examples

Example 1

eventIds = ["beat","flush"]periods = [2,3]runLimits = [3,2]horizon = 6return = ["2:beat","3:flush","4:beat","6:beat","6:flush"]

The events execute at 2:beat, 3:flush, 4:beat, then both at time 6 in ID order.

Example 2

eventIds = ["z","a"]periods = [4,4]runLimits = [1,1]horizon = 4return = ["4:a","4:z"]

Equal due times are ordered lexicographically by event ID.

Constraints

  • 0 <= eventIds.length = periods.length = runLimits.length <= 100000
  • 1 <= periods[i], horizon <= 1000000000
  • 0 <= runLimits[i] <= 100000
  • The returned log contains at most 200000 entries.

More Etched problems

  • Constant-Time Weighted Pick with an Alias TablePHONE SCREEN · Seen Nov 2026
  • DMA Stream DistributionPHONE SCREEN
See Etched hiring insights
Saved
class Solution {
    public String[] runPeriodicEvents(String[] eventIds, int[] periods, int[] runLimits, int horizon) {
      // Write your code here.
    }

}
Checking account…