FastPrepLRU Cache
Problems/LRU Cache

LRU Cache

Intuit logoIntuit● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Intuit intern onsite interview. The report asked for an LRU cache built from scratch but left out the operation format and limits on the numbers. Our version is about 94% the same as the reported question.

Implement a least recently used cache with fixed positive capacity, then process the operations in operations.

  • "PUT key value" inserts or updates a key. When a new key would exceed capacity, evict the least recently used key.
  • "GET key" returns the stored value, or -1 when the key is absent.

A successful GET and every PUT make that key the most recently used. A missing GET does not change recency. Return the results of all GET operations in their original order.

Build the cache behavior directly; do not use a library-provided LRU cache.

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]

GET 1 makes key 1 recent, so inserting key 3 evicts key 2.

Example 2

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

Updating key 4 changes its value to 9. Inserting key 5 later evicts it because capacity is 1.

Example 3

capacity = 2operations = ["GET 7","PUT 0 0","GET 0"]return = [-1,0]

The first lookup misses without changing the cache. Keys and values may be zero.

Constraints

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

More Intuit interview questions

  • Number of IslandsONSITE INTERVIEW · Seen Nov 2026
  • VIP and Regular Service SchedulerPHONE SCREEN · Seen Nov 2026
  • Employee Promotion OpportunitiesOA · Seen Oct 2026
  • Next Pascal Row CoefficientOA · Seen Oct 2026
  • Parse Router LogsOA · Seen Oct 2026
  • Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
  • Maximum Square-Free DivisorOA · Seen Oct 2026
  • Two Tribes from Taller-Person CountsOA · Seen Oct 2026
  • Shortest Path from an Encoded GraphOA · Seen Sep 2026
  • Oldest and Youngest EmployeesOA · Seen Sep 2026

Similar questions at other companies

  • LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • 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
  • 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 CacheOracle · ONSITE INTERVIEWOracle interview questions
  • Aligned Free-List Memory AllocatorHudson River Trading · ONSITE INTERVIEWHudson River Trading interview questions

Intuit interview experiences

  • Intuit OA: What It Tests (2026)
  • Intuit Software Engineering Intern - Full Stack OA Format
All Intuit interview questionsSee Intuit hiring insights
Saved
class Solution {
    public int[] runLRU(int capacity, String[] operations) {
        // Write your code here
    }
}
Checking account…