ML Interview Prep
Repository for Machine Learning Engineer (MLE) interview preparation materials and from-scratch algorithm implementations. Additional notebooks and resources will be added here.
📌 Current Status
Available Notebooks
MLE_Coding_Interview_Guide.ipynb: From-scratch implementations of core MLE coding interview algorithms with mathematical formulations, interview tips, and verification tests:
- Linear Regression (Vectorized Gradient Descent & Normal Equation)
- Logistic Regression (Vectorized Gradient Descent & Numerically Stable Sigmoid)
- K-Means Clustering (Random Initialization, Vectorized Broadcasting & List Comprehension)
- K-Nearest Neighbors (KNN) (Unified Pairwise Distance Matrix & $\mathcal{O}(N)$ Top-K)
- 2-Layer MLP with Backprop (Manual Multivariate Chain Rule in pure NumPy)
- Layer Normalization (NumPy & PyTorch implementations)
- Multi-Head Self-Attention (Scaled Dot-Product, Causal Masking & Projections in PyTorch)
- Low-Rank Adaptation (LoRA) (PEFT module with initialization trap handling & weight merging)
- Byte-Pair Encoding (BPE) (Subword tokenizer with pair-frequency statistics and greedy merging)
ML_LeetCode_Interview_Guide.ipynb: LeetCode-style algorithmic questions intersecting with Machine Learning, Probability, Retrieval, and Computer Vision in pure Python (no NumPy/PyTorch, standard library only):
- Weighted Random Sampling (Prefix Sums + Binary Search / LC 528)
- Reservoir Sampling (Uniform Streaming with $\mathcal{O}(1)$ Memory / LC 382 & LC 398)
- Sort Transformed Array (Convex Quadratic Parabola & Two Pointers / LC 360)
- Find Minimum of a Convex Function (Ternary Search & Divide-and-Conquer)
- Expected Calibration Error (ECE) (Bucket Binning & Reliability Gaps)
- Exact ROC-AUC with Tie Handling (Wilcoxon Rank-Sum Statistic & Fractional Ties)
- Precision-Recall Curve & Average Precision (Sweep-Line Threshold Integration)
- Dot Product of Two Sparse Vectors (Two Pointers & Binary Search for Imbalance / LC 1570)
- Top-K Cosine Similarity Retrieval (Min-Heap with
heapq in $\mathcal{O}(N \log K)$)
- TF-IDF & Inverted Index Document Retrieval (Lexical Search & Smoothed IDF)
- Streaming Running Median (Dual Heaps in $\mathcal{O}(\log N)$ / LC 295)
- Edit Distance & Word Error Rate (WER) (1D Space-Optimized DP / LC 72)
- Image Rotation by Arbitrary Angle (Inverse Coordinate Mapping & Bilinear Interpolation)
AI_Assisted_Coding_Interview_Guide.ipynb: Practical implementation and AI-assisted coding patterns (asked in companies like Shopify, LinkedIn, Meta, and similar tech organizations, with many other companies adopting comparable pair-programming or progressive implementation formats) featuring stateful simulation, robot navigation, game state machines, and progressive class design in pure Python (standard library only):
- Mars Rover / Grid Robot Command Engine (Cardinal directions, ray-step obstacle collision avoidance, jump distance, and undo action history)
- Blind-Grid Robot Room Cleaner (Sensory API exploration, virtual coordinate tracking, and blind DFS backtracking with physical orientation restoration)
- Cleaning Robot with Cycle Detection (Deterministic matrix navigation, obstacle/boundary reflection, and state-space cycle detection)
- Snake Game Engine with Growth & Collision (
deque body representation, sequential food ingestion, and tail-vacation vs. head collision order)
- Connect Four / Tic-Tac-Toe with $\mathcal{O}(1)$ Win Checking (Dynamic counter vectors for rows, columns, and diagonals with $\mathcal{O}(1)$ win evaluation)
- Battleship Fleet Coordinator (Grid coordinate validation, multi-deck ship geometry, shot hit/miss tracking, and fleet sinking coordinator)
- In-Memory Key-Field Database with TTL & Backup/Restore (Progressive 4-level architecture: CRUD, prefix scan, temporal TTL expiration, and remaining TTL restore)
- Cloud Storage Manager with User Quotas & Auto-Eviction (File indexing, user quota enforcement, largest-first tie-broken auto-eviction, and file compression)
- Text Editor with Undo/Redo & Find/Replace (Cursor navigation, buffer slicing, regex pattern replace count, and transactional command dual-stack undo/redo)
- Multi-Account Financial Ledger with Atomic Rollbacks (Double-entry transaction ledger, point-in-time binary search balance queries, and atomic transfer rollback)
- Sliding Window Log & Token Bucket Rate Limiter (Per-client timestamp window log pruning and continuous fractional refill token bucket)
- DAG Task Execution Engine with Dependency Resolution (Directed acyclic graph, Kahn's topological sort, circular cycle detection, and task output piping)
Available Guides & Playbooks
LeetCode_Patterns_and_Constraint_Shifts.md: A comprehensive reference guide and quick-review playbook detailing algorithmic problem patterns, constraint shifts, and complexity trade-offs for technical coding interviews:
- Constraint-to-Budget Engine: Determining target Big-O from input size
N (10^8 operations/sec rule, N <= 20 exponential vs. N >= 100,000 linear/logarithmic).
- The Master Invariant Principle: How breaking or granting core assumptions (sortedness, monotonicity, non-negativity, history-freeness, bounded values) transforms optimal data structures and complexity classes.
- Master Constraint-Shift Reference Matrix: Direct transition mappings across searching, two-sum, subarray sums, sequences, dynamic queries, knapsack, shortest paths, and streaming.
- Pattern Deep Dives: Subarrays vs. substrings vs. subsequences vs. subsets, binary search on the answer space, monotonic stacks/deques, DFS vs. BFS selection and space/memory trade-offs (balanced vs. skewed tree geometry, unweighted shortest paths vs. exhaustive backtracking), the graph shortest-path ladder, node reuse vs. simple paths, DP loop inversions and memoization soundness, interval sweep-line, memory-bounded streaming sketches, and non-comparison sorting.
- P, NP, NP-Complete & The 5 Escape Hatches: Practical strategies when facing NP-hard problems (small-
N bitmask DP, pseudo-polynomial DP, approximations, heuristics, structural restrictions).
- Hidden Complexity Traps & 60-Second Triage Funnel: Common pitfalls inside loops and a repeatable framework to analyze and articulate solutions under interview pressure.
🚀 Upcoming Additions
More topic-specific notebooks, ML system design walkthroughs, and practice problems will be added as preparation continues.