FastPrepMovie LRU Cache
Problems/Movie LRU Cache

Movie LRU Cache

Grab logoGrab● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand Grab report describes an LRU-cache exercise presented with movie names. We chose an access-only interface and returning the final order. Our version is about 82% the same as the reported question.

A movie cache holds at most capacity distinct movie names. Process the movie names in accesses from left to right.

  • Accessing a cached movie makes it most recently used.
  • Accessing a new movie inserts it as most recently used.
  • If insertion exceeds capacity, evict the least recently used movie.

Return the names remaining in the cache from most recently used to least recently used. If capacity is zero, return an empty array.

Function

recentMovies(capacity: int, accesses: String[]) → String[]

Examples

Example 1

capacity = 3accesses = ["Arrival","Heat","Up","Heat","Jaws"]return = ["Jaws","Heat","Up"]

Heat is refreshed before Jaws evicts the least-recent Arrival entry.

Example 2

capacity = 2accesses = ["A","B","A"]return = ["A","B"]

The final access moves A ahead of B.

Constraints

  • 0 <= capacity <= 100000.
  • 0 <= accesses.length <= 200000.
  • Every movie name is non-empty.

More Grab Phone Screen questions

  • Minimum Operations to Halve an Array SumPHONE SCREEN · Seen Nov 2021
  • Smallest Point with Maximum Inclusive Interval OverlapPHONE SCREEN · Seen Nov 2021

Similar questions at other companies

  • LRU CacheAthenahealth · PHONE SCREEN
  • 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
  • LRU Key-Value Cache OperationsCohesity · PHONE SCREEN
  • Least Recently Used CacheMicrosoft · OA · PHONE SCREEN · ONSITE INTERVIEWMicrosoft 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
All Grab interview questionsSee Grab hiring insights
Saved
class Solution {
    public String[] recentMovies(int capacity, String[] accesses) {
        // Return the final cache from most to least recent.
    }
}
Checking account…