PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates understanding of data structure design, sequence compression concepts (such as run-length patterns), and numeric algorithm efficiency for computing operations like the dot product, within the Coding & Algorithms domain, and it probes both conceptual understanding and practical application for large-scale data and engineering trade-offs. It is commonly asked to assess the ability to represent long repeating runs compactly and to reason about space/time complexity, iteration semantics, and edge cases such as differing run boundaries and accumulation/overflow concerns without relying on full decompression.

  • easy
  • Google
  • Coding & Algorithms
  • Software Engineer

Design compressed vector and compute dot product

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Onsite

## Problem You are given very long integer vectors where **many adjacent elements repeat** (e.g., long runs of the same value). Storing the full array is memory-expensive. ### Task 1. **Design a compact data structure** to store such a vector more efficiently than a raw `int[]`/`vector<int>`. 2. Using your compact representation, implement a method to compute the **dot product** of two vectors `A` and `B` of equal length `n`: \[ A \cdot B = \sum_{i=0}^{n-1} A[i] \times B[i] \] ### Requirements / Constraints - `n` can be very large (e.g., up to \(10^7\) or more), so avoid full decompression when possible. - Values fit in 32-bit signed integers; the dot product may require a 64-bit accumulator. - Your structure should support: - Building from an input array - Iterating through the logical sequence (implicitly) - Computing dot product between two compressed vectors efficiently ### Clarifications to state during interview - Assume “many repeats” primarily means **runs of identical adjacent values** are common. - Vectors are dense (not necessarily sparse / not mostly zeros). ### Deliverables - Describe the data structure and its space complexity. - Describe the dot product algorithm using the compressed form and its time complexity. - Provide key edge cases (e.g., negative values, different run boundaries, overflow concerns).

Quick Answer: This question evaluates understanding of data structure design, sequence compression concepts (such as run-length patterns), and numeric algorithm efficiency for computing operations like the dot product, within the Coding & Algorithms domain, and it probes both conceptual understanding and practical application for large-scale data and engineering trade-offs. It is commonly asked to assess the ability to represent long repeating runs compactly and to reason about space/time complexity, iteration semantics, and edge cases such as differing run boundaries and accumulation/overflow concerns without relying on full decompression.

Build run-length encodings of two equal-length vectors and compute their dot product without fully expanding the compressed form.

Constraints

  • Vectors have equal length

Examples

Input: ([1, 1, 1, 2, 2, 3], [4, 4, 5, 6, 6, 7])

Expected Output: 58

Input: ([0, 0, 0], [5, 6, 7])

Expected Output: 0

Input: ([-1, -1, 2], [3, 4, 5])

Expected Output: 3

Hints

  1. Advance through runs from both vectors, consuming the shorter remaining run.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Infection Spread on a Grid (Cellular Automaton) - Google (hard)
  • Most Active Users in a Live Communication Stream - Google (medium)
  • Boolean Expression Tree with Leaf Flips - Google (medium)
  • Streaming Points: Remove Any Pair Within a Distance - Google (medium)
  • Solve Rooms and Top-K Streams - Google (medium)