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
Fix Failing Python Tests
00:00
5 left

Fix Failing Python Tests

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 Karat technical screen, this task uses Wallet objects and a Ledger. Correct the existing state-update behavior, modify adjust, and add total_by_tier.

Contract

Implement run_cases(cases). Each case contains wallets with name, tier, and points, plus operations ["deposit"|"withdraw", name, amount]. Return one result per case with final balances and tier_totals.

Constraints

  • 1 <= len(cases) <= 100
  • 1 <= number of wallets in a case <= 1000
  • Wallet names are unique within a case
  • Wallet tiers are nonempty strings
  • Wallet points and operation amounts are nonnegative integers
  • Every withdrawal is valid and does not create a negative balance

Function Signature

def run_cases(cases):
Interviewer

Your question is Fix Failing Python Tests. 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.