PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Anthropic

Convert Samples into Event Intervals

Last updated: Apr 28, 2026

Quick Overview

This question evaluates understanding of array and sequence processing, run-length encoding concepts, and interval representation for time-ordered traces, including handling boundary conditions and filtering runs by a minimum length k.

  • medium
  • Anthropic
  • Coding & Algorithms
  • Machine Learning Engineer

Convert Samples into Event Intervals

Company: Anthropic

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given a time-ordered array `samples`, where `samples[i]` is the function name observed at integer timestamp `i`. Convert this trace into a list of events in the form `(function_name, start_time, end_time)`, where each event represents one maximal contiguous run of the same function. Use half-open intervals `[start_time, end_time)`. For example, if `samples = ["A", "A", "B", "B", "B", "A"]`, the output should be `[("A", 0, 2), ("B", 2, 5), ("A", 5, 6)]`. Follow-up: given an integer `k`, only treat a run as a valid event if the same function appears for at least `k` consecutive timestamps. Runs shorter than `k` should be discarded. Do not merge runs that were separated in the original trace, even if they have the same function name. Implement the transformation and discuss the time and space complexity.

Quick Answer: This question evaluates understanding of array and sequence processing, run-length encoding concepts, and interval representation for time-ordered traces, including handling boundary conditions and filtering runs by a minimum length k.

Related Interview Questions

  • Same-Domain Web Crawl (BFS) - Anthropic (medium)
  • Maximum-Length Unique-Character Subset - Anthropic (medium)
  • In-Memory Key-Value Database with Nested Transactions - Anthropic (medium)
  • Path Resolution with Symbolic Links - Anthropic (medium)
  • Banking System Simulation - Anthropic (medium)
|Home/Coding & Algorithms/Anthropic

Convert Samples into Event Intervals

Anthropic logo
Anthropic
Apr 7, 2026, 12:00 AM
mediumMachine Learning EngineerTechnical ScreenCoding & Algorithms
13
0
Practice Read
Loading...

You are given a time-ordered array samples, where samples[i] is the function name observed at integer timestamp i. Convert this trace into a list of events in the form (function_name, start_time, end_time), where each event represents one maximal contiguous run of the same function.

Use half-open intervals [start_time, end_time). For example, if samples = ["A", "A", "B", "B", "B", "A"], the output should be [("A", 0, 2), ("B", 2, 5), ("A", 5, 6)].

Follow-up: given an integer k, only treat a run as a valid event if the same function appears for at least k consecutive timestamps. Runs shorter than k should be discarded. Do not merge runs that were separated in the original trace, even if they have the same function name.

Implement the transformation and discuss the time and space complexity.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Anthropic•More Machine Learning Engineer•Anthropic Machine Learning Engineer•Anthropic Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.