FastPrepLeast Frequently Used Cache
Problems/Least Frequently Used Cache

Least Frequently Used Cache

NVIDIA logoNVIDIA● HardFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an NVIDIA phone screen for a full-time role. The report names a cache exercise. We kept the least-frequency eviction rule. We chose a finite set of commands, the tie policy, what counts as an update, and the input limits.

Our version is about 90% the same as the reported question.

Implement a least-frequently-used cache with capacity capacity. Start with an empty cache. Process each string in operations in order:

  • put key value inserts a new key or updates its value. A new key starts with frequency 1. Updating a stored key increases its frequency by 1.
  • get key returns its value and increases its frequency by 1 when present. Return -1 when absent; a miss changes no stored frequency.

Before inserting a new key into a full cache, remove the key with the smallest frequency. If frequencies tie, remove the least recently used key among them. Every successful get, update, and insertion makes that key most recently used within its frequency. A zero-capacity cache never stores anything.

Return the results of get operations in order. Each cache operation should take average O(1) time. The finite command list drives the cache interface.

Function

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

Examples

Example 1

capacity = 2operations = ["put 1 10","put 2 20","get 1","put 3 30","get 2","get 3","put 4 40","get 1","get 3","get 4"]return = [10,-1,30,-1,30,40]

Reading key 1 protects it from the first eviction. Before inserting key 4, keys 1 and 3 tie at frequency 2; key 1 is less recent and is evicted.

Example 2

capacity = 0operations = ["put 5 50","get 5"]return = [-1]

With zero capacity, the put stores no entry.

Constraints

  • For this exercise, assume 0 <= capacity <= 100000 and 0 <= operations.length <= 100000.
  • For this exercise, assume keys and values are integers in [0, 10^9].
  • Each command is exactly put key value or get key, with single spaces and valid integers.

More NVIDIA Phone Screen questions

  • Network Layer Execution OrderPHONE SCREEN · Seen Nov 2026
  • Paged KV Cache AccessPHONE SCREEN · Seen Nov 2026
  • Sliding Window Attention over a KV CachePHONE SCREEN · Seen Nov 2026
  • Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
  • Hash Partition OffsetsPHONE SCREEN · Seen Oct 2026
  • Filter Paginated Medical RecordsPHONE SCREEN · Seen Oct 2026
  • Parallel String Counts with a Custom Hash TablePHONE SCREEN · Seen Oct 2026
  • Simulate a Reference-Counted Smart PointerPHONE SCREEN · Seen Aug 2026
  • Streaming Top-K Frequent ElementsPHONE SCREEN · Seen Aug 2026
  • Merge Multiple Sorted StreamsPHONE SCREEN · Seen Aug 2026

Similar questions at other companies

  • LFU CacheFreshworks · PHONE SCREENFreshworks interview questions
  • LFU Cache with LRU Tie-BreakingRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • LFU CacheCitadel · PHONE SCREENCitadel interview questions
  • LFU CacheGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Least Frequently Used Cache SimulatorAdobe · PHONE SCREENAdobe interview questions
  • Windowed Key-Value MapConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
  • LFU CacheBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • LRU CacheAthenahealth · PHONE SCREEN
  • LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW

NVIDIA interview experiences

  • NVIDIA Full-Time SWE Onsite Scheduling: 1 Experience
  • NVIDIA OA: What It Tests (2026)
  • NVIDIA DevOps, QA and Infra Intern Interviews: 12 Experiences
  • NVIDIA Ignite Internship OA Experience
  • NVIDIA Software Intern Interview Questions: 9 Experiences
  • NVIDIA Ignite SWE Intern OA Questions: 6 Experiences
All NVIDIA interview questionsSee NVIDIA hiring insights
Saved
class Solution {
    public int[] processLfuCache(int capacity, String[] operations) {
        // Write your code here.
    }
}
Checking account…