PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Product / Decision Making/Goldman Sachs

Word Compression Algorithm

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a product manager's ability to reason about string compression and decompression techniques (run-length encoding), focusing on algorithmic trade-offs, correctness under edge cases, and time/space complexity analysis.

  • medium
  • Goldman Sachs
  • Product / Decision Making
  • Product Manager

Word Compression Algorithm

Company: Goldman Sachs

Role: Product Manager

Category: Product / Decision Making

Difficulty: medium

Interview Round: Take-home Project

##### Question Design an algorithm that compresses a string by replacing consecutive repeating characters with the character followed by the repeat count (e.g., "aaabbc" → "a3b2c1"). Describe the compression and decompression procedures. Specify how you would handle edge cases such as single-character runs, very long inputs, or cases where compression makes the string longer. Provide Big-O time and space complexity analysis.

Quick Answer: This question evaluates a product manager's ability to reason about string compression and decompression techniques (run-length encoding), focusing on algorithmic trade-offs, correctness under edge cases, and time/space complexity analysis.

Related Interview Questions

  • Lottery Coupon Winners Calculation - Goldman Sachs (medium)
Goldman Sachs logo
Goldman Sachs
Jul 4, 2025, 8:28 PM
Product Manager
Take-home Project
Product / Decision Making
7
0

String Compression and Decompression (Run-Length Encoding)

Problem

Design an algorithm that compresses a string by replacing consecutive repeating characters with the character followed by the repeat count. For example:

  • Input: "aaabbc"
  • Output: "a3b2c1"

Describe both the compression and decompression procedures.

Requirements

  1. Define the compression algorithm (encode) and the decompression algorithm (decode).
  2. Address edge cases:
    • Single-character runs (e.g., "c" → "c1").
    • Very long inputs and runs (e.g., millions of characters).
    • Cases where compression does not help or makes the string longer.
  3. Provide Big-O time and space complexity analysis.

Assumptions (make minimal, explicit choices)

  • Use a simple run-length encoding (RLE) scheme: for each run, emit a single character followed by its run length as a base-10 positive integer (no separators). Always include the count (even when it is 1), consistent with the example.
  • Characters are Unicode code points; counts are ASCII digits 0–9.
  • Input strings can include any characters, including digits; the format remains unambiguous because decoding reads exactly one character followed by one-or-more digits representing the count.

Solution

Show

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Product / Decision Making•More Goldman Sachs•More Product Manager•Goldman Sachs Product Manager•Goldman Sachs Product / Decision Making•Product Manager Product / Decision Making
PracHub

Master your tech interviews with 7,500+ 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.