Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Filter Collection by Criteria
00:00
5 left

Filter Collection by Criteria

EasyPython

Problem

Dataminr First Alert processes event records with fields such as category, confidence, severity, and acknowledgment status. Given a collection of alerts and a set of optional criteria, return every alert that satisfies all specified criteria, preserving the original order.

Formal Specification

Implement filter_alerts(alerts, criteria).

  • alerts is a list of dictionaries. Each dictionary contains id as a string, category as a string, confidence as a number from 0 to 1, severity as an integer from 1 to 5, and acknowledged as a boolean.
  • criteria is a dictionary. Supported optional keys are min_confidence, min_severity, categories, and acknowledged.
  • An alert matches only if it satisfies every criterion present in criteria.
  • categories is a list of accepted category strings. An empty list matches no categories.
  • Return a new list containing the original alert dictionaries in their input order.
  • Do not modify alerts or its dictionaries.

Constraints

  • 0 <= len(alerts) <= 10^5
  • Each alert contains id, category, confidence, severity, and acknowledged
  • 0 <= confidence <= 1
  • 1 <= severity <= 5
  • criteria contains only supported keys
  • An empty categories list matches no alerts

Function Signature

def filter_alerts(alerts, criteria):
Interviewer

Your question is Filter Collection by Criteria. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.