Cache Access Statistics
Updated
Problem statement
Process operations against an initially empty string cache:
PUT key valueinserts or overwriteskey.GET keyemitsHIT valuewhen the key exists, otherwiseMISS. 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 valueorGET 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