InterviewStack.io LogoInterviewStack.io

Algorithmic Complexity & Code-Level Optimization Questions

Reasoning about the time and space complexity of code and applying local optimizations that materially change performance. Covers Big-O analysis and performance modeling, data-structure selection, hot-loop and allocation reduction, and knowing when an algorithmic change beats micro-optimization. Emphasizes performance-aware coding grounded in complexity rather than premature tuning.

MediumTechnical
103 practiced
An algorithm runs in O(n * sqrt(n)) time but must scale to n up to 1e8. Propose practical algorithmic and engineering strategies to make this feasible: consider approximation, sampling, divide-and-conquer, precomputation, parallelization, and hardware acceleration. For each strategy provide expected asymptotic or constant-factor improvements and discuss tradeoffs in memory, accuracy, and implementation complexity.
MediumTechnical
95 practiced
Discuss performance and numerical stability trade-offs between float32, float16, and bfloat16 for training and inference. Explain how hardware (e.g., NVIDIA Tensor Cores, TPUs) changes these trade-offs and when mixed-precision training is safe or risky for model convergence and final accuracy.
MediumTechnical
94 practiced
Design an efficient streaming algorithm to approximate p50, p95, and p99 latencies for an online service handling ~10M events per day. Explain why you would pick t-digest, HDRHistogram, or the P^2 algorithm. Provide pseudocode for updating and querying your chosen data structure and analyze time and space complexity.
EasyTechnical
84 practiced
Estimate the RAM required to load a dataset of 12,000,000 samples where each sample has 300 float32 features and a 1-byte label. Show the raw data calculation and then include commonly overlooked overheads: numpy array metadata, Python object overhead if stored as a list of lists, and additional memory needed during training for Adam optimizer (assume Adam keeps two additional float32 tensors per parameter).
EasyTechnical
95 practiced
You need to estimate where time is spent during a single-node PyTorch training job: CPU preprocessing, GPU kernel execution, and PCIe transfers. Describe the minimal set of measurements and tools you would use to measure CPU vs GPU time and memory utilization. Explain concrete steps to distinguish a data-loading bottleneck from a compute or PCIe transfer bottleneck.

Unlock Full Question Bank

Get access to hundreds of Algorithmic Complexity & Code-Level Optimization interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.