PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Hebbia

Implement a Cache Snapshot Printer

Last updated: May 5, 2026

Quick Overview

This question evaluates understanding of LRU cache semantics, data structures for maintaining recency and eviction, and techniques for serializing or compressing state by grouping identical values while preserving ordering.

  • medium
  • Hebbia
  • Coding & Algorithms
  • Software Engineer

Implement a Cache Snapshot Printer

Company: Hebbia

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Implement an LRU-style cache and a snapshot-printing feature. The cache stores key-value pairs and has a fixed capacity. It should support normal cache operations such as inserting/updating a key and reading a key. When the capacity is exceeded, the least recently used entry should be evicted. Add a function `snapshot(cache)` that returns a printable representation of the current cache contents in recency order. Then extend the snapshot logic to support compressed output. Given a compression utility, group entries that have the same value. For example, if the cache snapshot contains: ```text A: 2 B: 2 ``` the compressed snapshot can be represented as: ```text 2 [A, B] ``` Clarify and implement how ordering should be preserved in the compressed output, especially when multiple values appear in the cache.

Quick Answer: This question evaluates understanding of LRU cache semantics, data structures for maintaining recency and eviction, and techniques for serializing or compressing state by grouping identical values while preserving ordering.

Related Interview Questions

  • Implement Ultimate Tic-Tac-Toe - Hebbia (medium)
Hebbia logo
Hebbia
Feb 6, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
1
0

Implement an LRU-style cache and a snapshot-printing feature.

The cache stores key-value pairs and has a fixed capacity. It should support normal cache operations such as inserting/updating a key and reading a key. When the capacity is exceeded, the least recently used entry should be evicted.

Add a function snapshot(cache) that returns a printable representation of the current cache contents in recency order.

Then extend the snapshot logic to support compressed output. Given a compression utility, group entries that have the same value. For example, if the cache snapshot contains:

A: 2
B: 2

the compressed snapshot can be represented as:

2 [A, B]

Clarify and implement how ordering should be preserved in the compressed output, especially when multiple values appear in the cache.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Hebbia•More Software Engineer•Hebbia Software Engineer•Hebbia Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

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