Two phases split across the session, roughly 25 minutes to debug and 35 to optimize.
Start by clarifying the expected interface and data shapes, then implement a minimal working version of fit and transform that handles the core logic correctly. Prioritize getting a runnable solution quickly, then optimize for edge cases and performance if time permits.
Pro tip: Write a quick test case or print statements to verify your implementation on a small example before running the full test suite; this catches shape mismatches and logic errors early.
Ask about the expected input/output formats, data types, and any specific behavior for fit and transform (e.g., handling missing values, categorical encoding). Confirm the time limit and available libraries.
Outline the skeleton of the class or functions, including __init__, fit, and transform methods. Decide what state needs to be stored during fit (e.g., means, vocabularies) and how transform will use it.
Write the simplest correct implementation that passes basic cases, focusing on core logic. Avoid premature optimization; use straightforward loops or vectorized operations if obvious.
Run the provided tests or create small examples to validate behavior. Fix errors one by one, checking shapes, types, and edge cases like empty inputs or unseen categories.
If time remains, improve performance (e.g., vectorization) and add robustness for edge cases. Ensure the code is clean and well-commented for readability.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.