FastPrepCache Access Statistics
Problems/Cache Access Statistics

Cache Access Statistics

Goldman Sachs logoGoldman Sachs● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Goldman Sachs onsite report asks for cache logic backed by ConcurrentHashMap, and for hit, miss, and per-key frequency counts. It does not give the operations, the return format, how updates work, or how eviction works. Our version has no eviction and handles a batch in time order. It keeps the statistics you can observe. Our version is about 82% the same as the reported question.

Process operations against an initially empty string cache:

  • PUT key value inserts or overwrites key.
  • GET key emits HIT value when the key exists, otherwise MISS. A hit increments that key's frequency by one.

After all operations, append STATS h m, where h and m are total hits and misses. Append each key with positive hit frequency as key:frequency in lexicographic key order. There is no capacity limit or eviction.

Function

trackCacheStatistics(operations: String[]) → String[]

Examples

Example 1

operations = ["PUT a 10","GET a","GET b","PUT b 20","GET b"]return = ["HIT 10","MISS","HIT 20","STATS 2 1 a:1 b:1"]

Both stored keys are hit once, and the first read of b is the only miss.

Example 2

operations = ["PUT x old","PUT x new","GET x","GET x"]return = ["HIT new","HIT new","STATS 2 0 x:2"]

The second PUT overwrites x without changing its read frequency.

Constraints

  • 0 <= operations.length <= 200000
  • Each command is exactly PUT key value or GET key.
  • Keys and values are nonempty ASCII tokens without whitespace.

More Goldman Sachs Onsite Interview questions

  • Best Average Student ScorePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Knight Probability in ChessboardONSITE INTERVIEW · Seen Nov 2026
  • Meeting RoomsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Minimum Meeting Rooms Without a Sweep LineONSITE INTERVIEW · Seen Oct 2026
  • First Non-Repeating CharacterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Root of the Largest TreePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Dungeon HealthONSITE INTERVIEW · Seen Sep 2026
  • Insert, Delete, And Get Random In Constant TimeONSITE INTERVIEW · Seen Sep 2026
  • Least Recently Used CacheONSITE INTERVIEW · Seen Sep 2026
  • Staircase Search In A Sorted MatrixONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Rectangle Point Coverage CountsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Transactional Key-Value StoreGrammarly · ONSITE INTERVIEW
  • LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
  • File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
  • Hash Map with Separate ChainingApplied Intuition · ONSITE INTERVIEWApplied Intuition interview questions
  • Camel CardsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
All Goldman Sachs interview questionsSee Goldman Sachs hiring insights
Saved
class Solution {
    public String[] trackCacheStatistics(String[] operations) {
      // write your code here
    }
}
Checking account…