← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Google SWE interview with a problem I hadn't seen framed quite this way before. The core idea was clean but the follow-up about doing the computation on compressed data without unpacking it is where things got interesting.

Questions Asked (1)

Q1

You have a long integer vector with lots of consecutive repeated values. Design a compact storage format that uses space proportional to the number of runs rather than the total length of the vector. Then, given two such compressed vectors of the same logical length, compute their dot product directly on the compressed form using a two-pointer approach, no decompression allowed.

Algorithms & Data StructuresTechnical Trade-offsSystem Design
Author's notes

The run-length encoding part came pretty naturally.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Propose a run-length encoding (RLE) scheme that stores each run as a (value, count) pair, achieving O(R) space where R is the number of runs. For the dot product, use two pointers to traverse both compressed vectors simultaneously, aligning runs by their logical positions and accumulating the product of overlapping segments. Emphasize that no decompression is needed and the time complexity is O(R1 + R2).

Pro tip: Mention that this approach is essentially a merge of two sorted lists of intervals, and highlight that it handles cases where runs partially overlap by splitting the overlap. Also, note that the same technique generalizes to other operations like addition or equality checks.

1. Define the compressed format

Propose storing the vector as a list of (value, count) pairs, where each pair represents a consecutive run of identical values. Explain that this uses space proportional to the number of runs, not the total length.

2. Set up two pointers

Initialize pointers i and j to the start of each compressed vector, and maintain remaining counts for the current runs. Also track the current logical position to know when runs end.

3. Iterate and compute overlap

While both pointers are within bounds, determine the length of the overlapping segment between the current runs: min(remaining count in run i, remaining count in run j). Multiply the values of the two runs by this overlap length and add to the dot product.

4. Advance pointers

After processing the overlap, decrement the remaining counts of both runs by the overlap length. If a run's remaining count becomes zero, advance its pointer to the next run. Continue until all runs are processed.

5. Analyze complexity and edge cases

State that the algorithm runs in O(R1 + R2) time and uses O(1) extra space. Discuss edge cases such as different numbers of runs, zero-length vectors, and runs with zero counts (if allowed).

Key Points to Mention

  • Run-length encoding (RLE) as the compact storage format.
  • Space complexity O(R) where R is the number of runs.
  • Two-pointer technique to traverse compressed vectors in parallel.
  • Overlap computation: min of remaining counts, multiply values, accumulate.
  • Time complexity O(R1 + R2) and no decompression.
  • Handling partial overlaps by splitting runs logically.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.