InterviewStack.io LogoInterviewStack.io

Error Handling and Code Quality Questions

Focuses on writing production quality code and scripts that are defensive, maintainable, and fail gracefully. Covers anticipating and handling failures such as exceptions, missing files, network errors, and process exit codes; using language specific constructs for error control for example try except blocks in Python or set minus e patterns in shell scripts; validating inputs; producing clear error messages and logs; and avoiding common pitfalls that lead to silent failures. Also includes code quality best practices such as readable naming and code structure, using standard libraries instead of reinventing functionality, writing testable code and unit tests, and designing for maintainability and observability.

EasyTechnical
0 practiced
Write a simple pytest unit test for a function `normalize_features(arr: np.ndarray) -> np.ndarray` which should raise a ValueError when the input contains NaNs or infinities. Show one well-structured test that checks both NaN and infinite cases by mocking input arrays.
MediumTechnical
0 practiced
Implement a Python context manager class `GPUContext` that acquires a GPU resource (simulate with an integer GPU id) and guarantees release even if the block raises an exception. The manager should log acquisition and release and raise a custom `GPUUnavailableError` if the requested GPU is not free. Sketch the class with __enter__/__exit__ implementations.
MediumTechnical
0 practiced
You have an existing training loop that currently swallows all exceptions and just prints 'error' before continuing. Refactor the pattern to: (a) properly log the error with context, (b) checkpoint model state before risky operations, (c) decide whether to abort training or skip a single batch, and (d) ensure the process exits with non-zero code on unrecoverable errors. Describe the concrete changes you'd make and why.
HardSystem Design
0 practiced
Design a safe model update process for a stateful recommender that requires coordinated updates to model weights, feature store mappings, and offline recomputation pipelines. The process should guarantee no partial updates are visible in production and provide rollback procedures. Outline components, orchestration, and failure modes.
HardTechnical
0 practiced
Implement a thread-safe LRU cache class in Python `PredictionCache` for storing recent model predictions keyed by request fingerprint. The class should support get(key) and put(key, value) and handle concurrent access, and ensure that attempts to use the cache while the model is reloading are safe (e.g., return a cache-miss when reloading). Sketch the implementation focusing on concurrency controls.

Unlock Full Question Bank

Get access to hundreds of Error Handling and Code Quality interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.