Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Large Codebase Bug Fix + New Methods
00:00
5 left

Large Codebase Bug Fix + New Methods

HardPython

Problem

Given a large codebase, find and fix a bug causing a failing test, then implement 2 new methods (explain approach before coding).

Asked in the karat_screen stage. For this exercise, the repository exposes a WordIndex class. Repair its count bookkeeping and implement insert(word) and count_prefix(prefix). The grader calls run_operations(operations) and expects outputs for query operations.

Contract

Each operation is ["insert"|"remove"|"count"|"prefix", value]. Return results for count and prefix operations in order.

Constraints

  • 1 <= len(operations) <= 10^4
  • Each word and prefix contains lowercase English letters
  • 1 <= len(word) <= 100
  • Removing an absent word has no effect
  • Duplicate words are allowed

Function Signature

def run_operations(operations):
Interviewer

Your question is Large Codebase Bug Fix + New Methods. 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
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.