Trace Logs at a Two-Second Cadence
Updated
Problem statement
For this exercise, start a virtual periodic logger at time 0 milliseconds and return its output events through durationMs.
- The first event occurs at
2000ms, then one event occurs every2000ms. - Include an event exactly at
durationMs, but none after it. There is no time-zero event. - Every event carries the supplied
messageunchanged.
Return events in increasing time order as [timestamp, message] rows. Write each timestamp as a base-10 number of milliseconds with no leading zeros. Use virtual time and return the events immediately.
This function models output events rather than implementing a real browser timer.
Function
tracePeriodicLogs(durationMs: int, message: String) → String[][]Examples
Example 1
durationMs = 5500message = "tick"return = [["2000","tick"],["4000","tick"]]Events occur at 2000 and 4000 ms; the next event at 6000 ms is beyond the horizon.
Example 2
durationMs = 1999message = "ready"return = []The first event is at 2000 ms, so this horizon contains no event.
Constraints
0 <= durationMs <= 1000000.1 <= message.length <= 100.- Every message character is printable ASCII, with a code from
32through126.
More Klaviyo interview questions
- Render Sidebar Labels as HTMLONSITE INTERVIEW · Seen Jul 2025
- Validate Input Against Length BoundsONSITE INTERVIEW · Seen Jul 2025
- Flatten JSON into Repeated Key-Value PairsONSITE INTERVIEW · Seen Oct 2023
- Conditionally Insert or Update RecordsONSITE INTERVIEW · Seen Jul 2022
- Progressive Parcel Tracking OperationsOA · Seen Aug 2026
- Banking Transfers, Account Merges, and Historical BalancesOA · Seen Jul 2025
- In-Memory Database with Permanent and Expiring ValuesOA · Seen Jul 2025
- File Storage with User Quotas, Merging, Backups, and RestoreOA · Seen Jun 2025
- Key-Value Locks with Waiting QueuesOA · Seen Sep 2024
Similar questions at other companies
- Container Ledger with TradesFlexport · ONSITE INTERVIEWFlexport interview questions
- Christmas Tree with N TiersVerily · ONSITE INTERVIEW
- Ring Buffer OperationsAmazon · ONSITE INTERVIEW
- Count Distinct Underwriting PII ValuesAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Bounded Word Guess SolverAtlassian · ONSITE INTERVIEWAtlassian interview questions
- Generate an Unbiased Bit from a Biased CoinGoogle · ONSITE INTERVIEWGoogle interview questions
- Insert After a Linked-List NodeAMD · ONSITE INTERVIEWAMD interview questions
- Document Edit EventsClickUp · ONSITE INTERVIEW
- Virtual Card Transaction ValidatorCapital One · ONSITE INTERVIEWCapital One interview questions
- Apply Overridden Integer TransformsOptimus Information · ONSITE INTERVIEWOptimus Information interview questions