InterviewStack.io LogoInterviewStack.io

Code Quality and Defensive Programming Questions

Covers writing clean, maintainable, and readable code together with proactive techniques to prevent failures and handle unexpected inputs. Topics include naming and structure, modular design, consistent style, comments and documentation, and making code testable and observable. Defensive practices include explicit input validation, boundary checks, null and error handling, assertions, graceful degradation, resource management, and clear error reporting. Candidates should demonstrate thinking through edge cases such as empty inputs, single element cases, duplicates, very large inputs, integer overflow and underflow, null pointers, timeouts, race conditions, buffer overflows in system or embedded contexts, and other hardware specific failures. Also evaluate use of static analysis, linters, unit tests, fuzzing, property based tests, code reviews, logging and monitoring to detect and prevent defects, and tradeoffs between robustness and performance.

HardTechnical
24 practiced
Your company uses a large monorepo with thousands of ML projects. Propose a scalable static analysis and linting approach that gives fast feedback to developers without running full checks on unrelated projects. Cover incremental analysis, per-PR checks, baseline suppression, caching analysis artifacts, and developer tooling for local fast checks.
HardTechnical
28 practiced
Using Hypothesis or a custom generator, design property-based tests for a deep learning training loop that assert important invariants: (1) loss on a tiny synthetic dataset decreases after a few steps, (2) gradients and parameters remain finite, (3) a saved checkpoint can be loaded and reproduce inference outputs. Provide code sketches and explain strategies to reduce flakiness from randomness.
MediumSystem Design
27 practiced
You're training a large model on a shared GPU cluster. Describe defensive strategies to avoid OOM and job eviction: dynamic batch sizing, gradient accumulation, memory-aware data loaders, checkpointing on OOM, automatic retries on preemption, and graceful degradation to CPU for small jobs. Sketch a Python training loop with safe checkpointing and OOM handling patterns.
EasyTechnical
30 practiced
Explain what fuzz testing is and how it applies to ML pipelines. Give concrete examples of inputs to fuzz (image bytes, CSV lines, serialized protobufs) and list tools suitable for Python/ML ecosystems. Describe how to integrate simple fuzzing runs into CI for preprocessing modules to catch crashes from corrupted inputs.
MediumTechnical
25 practiced
Write property-based tests using Hypothesis for a normalization function normalize_vector(x) that takes a 1D numpy array and returns a unit-norm array. Tests should assert invariants: (1) non-zero vectors yield norm ≈ 1, (2) zero vector returns zero vector, (3) function preserves dtype within numeric types, (4) NaN/inf handling policy. Provide example Hypothesis strategies for numeric arrays and explain tolerances.

Unlock Full Question Bank

Get access to hundreds of Code Quality and Defensive Programming interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.