PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW
|Home/Coding & Algorithms/Anthropic

Convert State Stream to Events

Last updated: Apr 19, 2026

Quick Overview

This question evaluates a candidate's ability to process sequential categorical data by identifying and summarizing consecutive runs, reason about time and space complexity, and apply length-based filtering of events.

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

Convert State Stream to Events

Company: Anthropic

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given an array `states` where `states[i]` is the categorical output of a monitoring function at timestamp `i`. Consecutive equal values belong to the same event. Write a function that converts this stream into a list of events of the form `(value, start_index, end_index)`, where `start_index` and `end_index` are inclusive. Example: - Input: `['A', 'A', 'B', 'B', 'B', 'A']` - Output: `[('A', 0, 1), ('B', 2, 4), ('A', 5, 5)]` Follow-up: given an integer `k`, only runs with length at least `k` should be considered valid events. Any consecutive run shorter than `k` should be excluded from the output. Implement the function and analyze its time and space complexity.

Quick Answer: This question evaluates a candidate's ability to process sequential categorical data by identifying and summarizing consecutive runs, reason about time and space complexity, and apply length-based filtering of events.

Related Interview Questions

  • Convert Samples into Event Intervals - Anthropic (medium)
  • Build a concurrent web crawler - Anthropic (medium)
  • Implement a Parallel Image Processor - Anthropic (medium)
  • Implement a Batch Image Processor - Anthropic (medium)
  • Implement a crash-resilient LRU cache - Anthropic
Anthropic logo
Anthropic
Apr 6, 2026, 12:00 AM
Machine Learning Engineer
Onsite
Coding & Algorithms
45
0
Coding Console
Loading...

You are given an array states where states[i] is the categorical output of a monitoring function at timestamp i. Consecutive equal values belong to the same event.

Write a function that converts this stream into a list of events of the form (value, start_index, end_index), where start_index and end_index are inclusive.

Example:

  • Input: ['A', 'A', 'B', 'B', 'B', 'A']
  • Output: [('A', 0, 1), ('B', 2, 4), ('A', 5, 5)]

Follow-up: given an integer k, only runs with length at least k should be considered valid events. Any consecutive run shorter than k should be excluded from the output.

Implement the function and analyze its time and space complexity.

Comments (0)

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 7,500+ 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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.