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
Array Filtering Without Built-ins
00:00
5 left

Array Filtering Without Built-ins

EasyPython

Problem

Tyfone's Ozone digital banking experience displays transaction activity that users may narrow by transaction type and minimum amount. Given an array of transaction records, return a new array containing only records that satisfy both criteria, without using Python's built-in filter function or mutating the input.

Preserve the original order of the matching records. Use an explicit loop. Converting allowed_types to a set is permitted and encouraged for efficient membership checks.

Formal Specification

Implement filter_transactions(transactions, min_amount, allowed_types).

  • transactions is a list of dictionaries. Each dictionary contains an id string, a type string, and an amount number.
  • min_amount is a non-negative integer or float.
  • allowed_types is a list of transaction-type strings.
  • Return a new list containing each transaction whose amount is greater than or equal to min_amount and whose type appears in allowed_types.

Example 1: transactions = [{"id": "t1", "type": "card", "amount": 42}, {"id": "t2", "type": "ach", "amount": 80}], min_amount = 50, allowed_types = ["ach"] returns [{"id": "t2", "type": "ach", "amount": 80}] because only t2 satisfies both conditions.

Example 2: transactions = [{"id": "t1", "type": "card", "amount": 25}, {"id": "t2", "type": "card", "amount": 100}], min_amount = 25, allowed_types = ["card"] returns both records in their original order.

Constraints

  • 0 <= len(transactions) <= 100,000
  • 0 <= len(allowed_types) <= 100
  • 0 <= transaction.amount, min_amount <= 10^9
  • Each transaction contains valid id, type, and amount fields
  • The input list must not be mutated

Function Signature

def filter_transactions(transactions, min_amount, allowed_types):
Interviewer

Your question is Array Filtering Without Built-ins. 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.