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
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
Get started
Polymorphism in Real-World Code
00:00
5 left

Polymorphism in Real-World Code

HardPython

Problem

Write a program to demonstrate polymorphism in a real-world scenario.

Implement process_documents(documents) using a shared document interface and separate subclasses for invoices, forms, and contracts. Each subclass must override the same processing method, and the main function must process all inputs polymorphically without type-specific calculation logic in its iteration loop.

Input is a list of dictionaries. Each dictionary contains kind and fields required by that kind. Return an object containing per-document results and the total cost.

Supported calculations: invoices cost pages * 2 plus 5 for urgent priority, forms cost pages + attachments * 2, and contracts cost pages * 3 + clauses.

Constraints

  • 0 <= len(documents) <= 10000
  • Each document kind is one of: invoice, form, contract
  • Invoice pages and form pages are nonnegative integers
  • Invoice priority is either normal or urgent
  • Form attachments and contract clauses are nonnegative integers

Function Signature

def process_documents(documents):
Interviewer

Your question is Polymorphism in Real-World Code. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.