Interview questions with answer breakdowns — Page 50 of 52
Browse page 50 of Offer.cc interview question and answer breakdowns with reasoning, implementation details, follow-ups, and public sources.
Coding interview: How do you sample uniformly from an unknown-length stream?
Use reservoir sampling to maintain k equally likely items in one pass with O(k) memory, proving the invariant and handling boundaries.
How Would You Design a Distributed Unique ID Generator?
Derive a Snowflake bit layout from capacity constraints, handle clock rollback, worker identity, sequence exhaustion, and multi-region failures, then compare UUIDv7 and segment allocation.
Evaluate a Classifier on Imbalanced Data
Derive classification metrics and a decision threshold from the confusion matrix, review capacity, and error costs, then explain the distinct roles of AUROC, precision-recall, calibration, and base-rate monitoring.
Coding interview: How do you maximize reward with non-overlapping jobs?
Use weighted interval scheduling to connect sorting, binary search, and dynamic programming, with precise boundaries, proof, complexity, and reconstruction.
How Would You Design a Distributed Job Scheduler?
Design a multi-tenant scheduler for one-time and cron jobs using occurrence identities, sharded time indexes, and at-least-once delivery, while handling synchronized peaks, misfires, time zones, cancellation races, and recovery.
Detect and Prevent Data Leakage in Machine Learning
Use a fraud model to define a prediction-time contract, investigate target, temporal, entity, and preprocessing leakage, and build credible splits, cross-validation, and final holdout evaluation.
Coding Interview: How Do You Implement a Dynamic Array and Prove Amortized O(1) Append?
Use capacity invariants, geometric growth, and an amortized proof to implement an indexable dynamic array and explain space and worst-case costs.
Design a Multi-Channel Notification System
Using one billion channel-delivery tasks per day as an interview assumption, design a notification system for both OTPs and marketing campaigns, with priority isolation, honest delivery states, out-of-order callbacks, retries, and testable recovery.
Handle Late and Out-of-Order Events in Stream Processing
Use hourly revenue to derive a stream-processing design from event time, watermarks, allowed lateness, and deduplication state, including corrections, state cleanup, failure recovery, and offline reconciliation.
Coding Interview: How would you return the K most frequent words?
Use frequency counting, a custom min-heap, and a precise frequency/lexicographic comparator to return Top K words in O(n log k) time.
System design interview: Enforce a global rate limit across regions
Design quota leasing for a global API limit, quantify overshoot during partitions, rebalance hot regions, and choose explicit fail-open or fail-closed behavior.
Coding interview: How do you implement a calendar that rejects overlaps?
Use half-open intervals, predecessor and successor lookup, and an ordered map to solve My Calendar I with clear boundaries and complexity.
Coding interview: Debug a broken two-heap streaming median
Diagnose a MedianFinder that returns wrong values after adversarial insertions by restoring heap ordering, size, empty-state, and overflow invariants.
Coding interview: How would you implement an O(1) minimum stack?
Maintain a prefix-minimum stack so push, pop, top, and getMin run in O(1), including duplicate minima and empty-stack behavior.
Coding Interview: Implement a Bloom Filter
Implement add and mightContain for a Bloom filter, then explain false positives, sizing, deletion limits, and tests.
Coding Interview: Implement a Thread-Safe Read-Write Lock
Implement a read-write lock with a mutex and condition variables, then reason about fairness, upgrades, and failure cases.
Coding Interview: Implement a TTL Cache with Expiration
Use a hash table, expiration timestamps, cleanup, and concurrency rules to implement a testable TTL cache.
Coding Interview: How Would You Implement an Interval Set with Merge and Query?
Implement a normalized set of non-overlapping intervals with add, remove, point lookup, and range overlap queries, including boundary and complexity reasoning.
Coding Interview: How Would You Implement a Mutable Priority Queue with Update and Remove?
Use a heap, an index map, and lazy deletion to implement an updateable priority queue, covering stable ties, removal, stale entries, and complexity proofs.
Coding Interview: How Do You Design a Resumable Batched Iterator?
Start from the hasNext/next contract and design an iterator that reads remote pages, resumes safely, avoids duplicates, and propagates failures.
Coding Interview: Implement a Snapshot Array
Design a versioned array with per-index change histories, coalesced writes, and predecessor binary search, then prove the time, space, and snapshot semantics.
Coding Interview: Minimum Meeting Rooms
Turn meeting intervals into concurrent resource usage, compute the minimum room count with a two-array sweep line, and prove optimality through overlap depth, including half-open endpoints, tied events, heap alternatives, and room-assignment follow-ups.
Coding Interview: Solve Alien Dictionary with Topological Sort
Infer an unknown alphabet from a sorted word list by extracting only justified precedence edges. Learn the invalid-prefix rule, cycle detection, correctness proof, ambiguity checks, and adversarial tests for a complete interview answer.
Coding Interview: Count Number of Islands With Iterative DFS
Derive an in-place iterative DFS from connected-component modeling, explain why cells must be marked when pushed, and cover correctness, complexity, boundary tests, and alternatives.