Speed Up a Slow Search Log Aggregation Script

Last updated: November 29, 2026

Quick Overview

A Python script that counts queries per country from a large search log builds a report with string concatenation, membership checks on a list, and repeated parsing; identify the hot spots and rewrite it to run in linear time and bounded memory.

Google
Software Engineering Fundamentals
Data Engineer
Google
November 29, 2026
Data Engineer
Phone Screen
Software Engineering Fundamentals
Easy

0

0

0 solved


A Python script that counts queries per country from a large search log builds a report with string concatenation, membership checks on a list, and repeated parsing; identify the hot spots and rewrite it to run in linear time and bounded memory.

Google data engineers and SWEs routinely inherit pipelines that worked on samples and fall over on real log volume. The screen checks that you can spot accidental quadratic behavior and know idiomatic fixes before reaching for a cluster.

What the Interviewer Expects
  • Identify the O(n^2) pieces in the original loop
  • Replace list membership with a set or dict
  • Stream the input instead of loading it all
  • Build output with join instead of repeated concatenation
  • Measure before and after with a profiler
Key Topics to Cover
profiling
time complexity
Python performance
streaming
hash maps
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you profile this to confirm the hotspot?
  • What changes if the file is 2 TB?
  • When would you move this to Flume or Beam?
  • How would you compute the top 10 countries without sorting everything?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

The original code, roughly:

lines = open(path).readlines() countries, counts, report = [], [], "" for line in lines: c = line.split("\t")[2] if c not in countries: # O(k) scan ...
High-Level Design

Three problems. readlines() loads the whole file, so memory scales with input. in and .index on a list are linear in the number of distinct countries, run twice per line, making the loop O(n * k...


Submit Your Answer
Markdown supported