Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Trending in AI
Hot
Agentic AI EngineerForward-Deployed EngineerGenAI EngineerAI Architect
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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
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 the 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

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.