FastPrepLRU Cache Snapshot Printer
Problems/LRU Cache Snapshot Printer

LRU Cache Snapshot Printer

Hebbia logoHebbia● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Hebbia onsite interview. A public Hebbia page gives a fixed-capacity LRU cache, snapshots in recency order, and compression of equal values. We fixed the exact output punctuation and the order of the groups, so the output is always the same. Our version is about 95% the same as the reported question.

Process operations on a fixed-capacity LRU cache. PUT key value inserts or updates an entry and contributes null. GET key contributes its value, or the empty string when absent, and makes a hit most recently used. Evict the least recently used entry after an overflowing PUT.

SNAPSHOT contributes a compressed representation from most to least recent. Scan entries in that order, group keys with equal values, keep value groups in first-appearance order, and format each group as value:[key1,key2], joined with semicolons.

Function

runCacheSnapshots(capacity: int, operations: String[][]) → String[]

Examples

Example 1

capacity = 2operations = [["PUT","A","2"],["PUT","B","2"],["SNAPSHOT"],["GET","A"],["SNAPSHOT"]]return = ["null","null","2:[B,A]","2","2:[A,B]"]

Snapshot order follows recency, and a GET moves A to the front.

Example 2

capacity = 2operations = [["PUT","A","x"],["PUT","B","y"],["PUT","C","x"],["GET","A"],["SNAPSHOT"]]return = ["null","null","null","","x:[C];y:[B]"]

A is evicted; groups retain the first value appearance in recency order.

Constraints

  • 1 <= capacity <= 1000
  • 1 <= operations.length <= 100000
  • Keys and values contain no comma, colon, brackets, or semicolon.

More Hebbia interview questions

  • Detect a Winner on a 3x3 Tic-Tac-Toe BoardONSITE INTERVIEW · Seen Jun 2026
  • Ultimate Tic-Tac-Toe Move SimulatorPHONE SCREEN · Seen May 2026
  • Most Relevant Text SpanPHONE SCREEN · Seen Apr 2025

Similar questions at other companies

  • LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
  • Least Recently Used CacheMicrosoft · OA · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • LRU CacheAMD · ONSITE INTERVIEWAMD interview questions
  • LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • Least Recently Used CacheByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
  • LRU Cache with Hit and Miss CountersLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Least Recently Used CacheGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • LRU CacheIntuit · ONSITE INTERVIEWIntuit interview questions
  • LRU CacheOracle · ONSITE INTERVIEWOracle interview questions
See Hebbia hiring insights
Saved
class Solution {
    public String[] runCacheSnapshots(int capacity, String[][] operations) {
      // Write your code here.
    }

}
Checking account…