Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Transform and Filter Data

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

Your question is Transform and Filter Data. 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

In an Informatica Cloud Data Integration interface, users need to preview records after applying configurable filters and field transformations. Implement transform_records to filter an array of record objects and return transformed copies without mutating the input.

Formal Specification

The function receives records, a list of dictionaries, and criteria, a dictionary containing any of these optional keys:

  1. allowed_statuses: list of accepted status strings. A record passes when its status is included.
  2. min_score: numeric lower bound, inclusive. Records without a numeric score fail this filter.
  3. required_tags: list of tags. A record must contain every required tag in its tags array.
  4. name_contains: case-insensitive substring that must occur in the record's name.
  5. include_fields: fields to retain in each output record. If omitted, retain all fields.
  6. rename: mapping from source field names to output field names. Apply this only to retained fields.

All specified filters must pass. Preserve record order. Missing fields fail only the filter that requires them. Return a new list and do not mutate any input dictionary.

Constraints

  • 0 <= len(records) <= 10^4
  • Each record contains string keys and JSON-compatible values
  • required_tags and include_fields contain unique strings
  • Rename targets are unique and do not collide with retained, unrenamed fields
  • All specified filters must pass

Function Signature

def transform_records(records, criteria):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output