Katkat

How to handle huge inputs?

GoogleSoftware Engineer · Onsite

Last updated

Answer the coding interview follow-up "what if the input is huge?" Covers memory checks, streaming, chunking, external sort, approximate structures, distributed processing, and engineering tradeoffs.

In a coding interview, after solving an in-memory algorithmic problem, the interviewer asks: "What would you do if the input were extremely large?"

Give a structured answer that explains how to reason from constraints to design choices.

Constraints & Assumptions

  • The original problem could be common, such as interval scheduling, grouping, counting, or sorting.
  • The follow-up is general rather than tied to one exact algorithm.
  • Discuss exact versus approximate answers, memory limits, streaming, chunking, external storage, and distributed processing.
  • Do not jump straight to "use distributed systems" without explaining why.

Clarifying Questions to Ask

  • Does the full input fit in memory?
  • Is the input static, streamed, or continuously updated?
  • Do we need an exact answer or is approximation acceptable?
  • Do we need global ordering, random access, or only a summary?
  • Are we constrained by memory, disk I/O, network, latency, or throughput?
  • Is this single-machine or multi-machine?

Follow-up questions

  • How would your answer change for a problem requiring sorting?
  • What if there is severe key skew?
  • What approximate data structures might help?
  • How would you test correctness for chunked processing?