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.

MediumTechnical
31 practiced
You observe flaky unit tests in CI that occasionally fail depending on random seeds and environment. Outline a methodical debugging and remediation plan: how to reproduce failures locally, make tests deterministic, decide when to seed vs allow randomness, and how to detect flaky tests proactively in CI.
HardTechnical
21 practiced
Describe in detail how to achieve numerical stability for mixed-precision training across frameworks (PyTorch/TensorFlow) and hardware (NVIDIA Ampere and earlier GPUs). Cover dynamic/static loss scaling, stable layer implementations (LayerNorm), using fp32 copies for weights/optimizer states, avoiding in-place ops that break autograd, and testing strategies to verify correctness.
MediumTechnical
21 practiced
In a high-throughput inference service, adding try/except and validation on every request increased latency. Propose patterns to balance robustness and throughput: fast-path checks, sampled deep-validation, bulk validation, blacklisting, and async / offline verification. Provide concrete examples and explain the trade-offs.
HardTechnical
27 practiced
Design an automated stress-testing and fuzzing framework for a text-generation API to detect safety issues (prompt injection), performance bottlenecks, and stability problems on malformed inputs. Describe prompt-generation strategies, concurrency/rate profiles, metrics to collect (latency, memory, hallucination rate), and automated triage logic for failures.
MediumSystem Design
30 practiced
Design a CI pipeline for ML model development that includes: unit tests, data-contract checks, model validation (train on tiny data + smoke evaluate), model artifact signing, and promotion from staging to production. Describe tools (e.g., GitHub Actions, Jenkins, MLflow), gating rules, and strategies to keep CI times reasonable.

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.