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
OOP Program Demonstration
00:00
5 left

OOP Program Demonstration

MediumPython

Problem

DTCC CTM receives trade instructions for multiple asset classes. Implement an object-oriented validator that uses abstraction and polymorphism to apply the correct validation rules without placing all asset-specific logic in one conditional-heavy function.

Create an abstract TradeRule class with a validate(trade) method. Implement EquityRule, BondRule, and OptionRule subclasses. The validate_trades function must select the appropriate rule for each instruction and return validation results in the original order.

Formal Specification

Input trades is a list of dictionaries. Every dictionary contains id, asset_type, quantity, price, and settlement_days. Option trades also contain strike.

Return a list of dictionaries with id, valid, and errors. valid is true only when no rules are violated. Error messages must use the exact strings defined below.

  • Equity: quantity must be positive, price must be positive, and settlement must be 1 or 2 days.
  • Bond: quantity must be positive, price must be between 0 and 100 inclusive, and settlement must be between 1 and 3 days.
  • Option: quantity must be positive, price must be nonnegative, strike must be positive, and settlement must be exactly 1 day.
  • Unknown asset types produce one error: Unknown asset type.

Constraints

  • 1 <= len(trades) <= 10^4
  • Each trade contains the required fields for its asset type
  • Numeric values fit standard Python integer or floating-point ranges
  • Asset types are case-sensitive
  • Output order must match input order

Function Signature

def validate_trades(trades):
Interviewer

Your question is OOP Program Demonstration. 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.