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
Debug and Implement in Python
00:00
5 left

Debug and Implement in Python

HardPython

Problem

Given several Python classes/objects with failing tests, find which functions' tests fail, explain why, and fix them; then modify one function and write a new function.

Asked in the Round not visible stage. One sub-question modifies an existing function, and the other adds a new function. Implement the corrected classes and run_tests(cases), which returns the names of failing tests.

Contract

Rewards.points(amount) returns two points per complete $10, plus 10 bonus points when amount >= 100. Card.mask(number) masks every digit except the final four. Card.redeem(balance, cost) returns the remaining balance, or -1 when funds are insufficient.

Constraints

  • Each case contains name, function, args, and expected keys
  • Function names are Rewards.points, Card.mask, or Card.redeem
  • Amounts, balances, and costs are non-negative integers
  • The number of test cases is at most 10^4

Function Signature

def run_tests(cases):
Interviewer

Your question is Debug and Implement in Python. 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.