Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Filter Collection by Criteria

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Filter Collection by Criteria. Start with the requirements on the right.

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.

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output