PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches

Quick Overview

This question evaluates proficiency in data manipulation and algorithmic reasoning in Python, covering event filtering, stable sorting, deduplication by identifier, timestamp windowing, and analysis of time and space complexity.

  • Medium
  • Affirm
  • Data Manipulation (SQL/Python)
  • Software Engineer

Implement and debug event filtering in Python

Company: Affirm

Role: Software Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: Medium

Interview Round: Onsite

You are given a list of event dictionaries with keys: id (str), type (str), ts (int, seconds since epoch), payload (dict). Implement filter_events(events, include_types=None, exclude_types=None, start_ts=None, end_ts=None, limit=None, dedupe_by_id=False) -> List[dict] with the following behavior: - If include_types is provided, return only events whose type is in include_types. - If exclude_types is provided, remove events whose type is in exclude_types (after applying include_types if both are provided). - Keep events whose ts is within the inclusive window [start_ts, end_ts] when the bounds are provided. - Return results in ascending ts order; if ts ties, preserve original input order (stable sort). - If limit is provided, return the earliest limit events after filtering and sorting. - If dedupe_by_id is True, keep only the event with the largest ts for each id. - Discuss time and space complexity and how you would handle already-sorted input. Debugging sub-part: Identify and fix the bugs in the following snippets and explain tests that would catch them. A) def filter_types(events, t): return [e for e in events if e['type'] is t] B) def filter_events(events, include=set()): return [e for e in events if e['type'] in include]

Quick Answer: This question evaluates proficiency in data manipulation and algorithmic reasoning in Python, covering event filtering, stable sorting, deduplication by identifier, timestamp windowing, and analysis of time and space complexity.

Last updated: Mar 29, 2026

Related Coding Questions

  • Analyze Loan Payments Using Pandas for Key Insights - Affirm (Medium)
  • Write SQL for Transactions and Customers - Affirm (Medium)

Loading coding console...

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.