FastPrepLeast Recently Used Cache
Problems/Least Recently Used Cache

Least Recently Used Cache

Illumio logoIllumio● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Illumio phone screen. The report names the standard least-recently-used cache task. It does not give a function interface that works across languages or the exact operation rules. Here we use the usual get and put behavior and a fixed batch of operations with a fixed outcome.

Process a finite ordered sequence of operations on a least recently used cache with capacity capacity.

  • PUT key value inserts or updates key. A successful write makes that key the most recently used. If inserting a new key would exceed the capacity, first evict the least recently used key.
  • GET key returns the stored value, or -1 when the key is absent. A successful lookup makes the key the most recently used; a missing lookup does not change the cache.

Return the integer results of the GET operations in encounter order. A PUT operation produces no result. Every operation uses decimal integers separated by one space.

Function

runLRU(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"]return = [10,-1,30]

Reading key 1 makes it the most recently used entry, so inserting key 3 evicts key 2.

Example 2

capacity = 1operations = ["PUT 5 7","PUT 5 9","GET 5","PUT 6 4","GET 5"]return = [9,-1]

Updating key 5 replaces its value without increasing the cache size. Inserting key 6 later evicts it.

Example 3

capacity = 3operations = ["GET 8","PUT 8 0","GET 8"]return = [-1,0]

The first lookup misses. After the insertion, the stored value 0 is returned normally.

Constraints

  • 1 <= capacity <= 200000.
  • 1 <= operations.length <= 200000.
  • Every operation is exactly GET key or PUT key value.
  • 0 <= key, value <= 10^9.

More Illumio interview questions

  • Exclusive Function TimePHONE SCREEN · Seen Oct 2026
  • Lexicographic Dependency OrderPHONE SCREEN · Seen Oct 2026
  • Time-Based Key-Value DatabaseONSITE INTERVIEW · Seen Jul 2026

Similar questions at other companies

  • LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
  • LRU Key-Value Cache OperationsCohesity · PHONE SCREEN
  • Least Recently Used CacheMicrosoft · OA · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • Least Recently Used CacheByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
  • LRU CacheCoupang · PHONE SCREEN
  • LRU CacheBlinkit · PHONE SCREENBlinkit interview questions
  • LRU Cache with Thread-Safety Follow-UpSnap Inc. · PHONE SCREENSnap Inc. interview questions
  • LRU Key-Value Cache OperationsNVIDIA · PHONE SCREENNVIDIA interview questions
All Illumio interview questionsSee Illumio hiring insights
Saved
class Solution {
    public int[] runLRU(int capacity, String[] operations) {
        // Write your code here.
    }
}
Checking account…