FastPrepLRU Cache Operations
Problems/LRU Cache Operations

LRU Cache Operations

Bloomberg LP logoBloomberg LP● MediumNEW GRADFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in several firsthand Bloomberg new-grad phone and onsite interviews. In our version, you build the standard LRU cache with a fixed capacity and get and put operations.

Process a sequence of operations on a least recently used (LRU) cache with a fixed positive capacity.

The cache starts empty. The parallel arrays operations and arguments describe the calls in order:

  • get has arguments [key]. Return the stored value, or -1 when the key is absent. A successful get makes that key the most recently used.
  • put has arguments [key, value]. Insert or update the key and make it the most recently used. If inserting a new key would exceed capacity, first evict the least recently used key.

Return an array containing the results of the get operations, in operation order. A put operation produces no result.

Function

runLruCache(capacity: int, operations: String[], arguments: int[][]) → int[]

Examples

Example 1

capacity = 2operations = ["put","put","get","put","get","get"]arguments = [[1,1],[2,2],[1],[3,3],[2],[3]]return = [1,-1,3]

Reading key 1 makes it most recent. Inserting key 3 then evicts key 2, so the final two reads return -1 and 3.

Example 2

capacity = 1operations = ["put","put","get","put","get"]arguments = [[5,10],[5,20],[5],[6,30],[5]]return = [20,-1]

Updating key 5 changes its value without increasing the cache size. Inserting key 6 later evicts key 5 because the capacity is 1.

Constraints

  • 1 <= capacity <= 10^5
  • 1 <= operations.length <= 2 * 10^5
  • operations.length == arguments.length
  • Each operation is exactly get or put.
  • A get row contains exactly one integer, and a put row contains exactly two integers.
  • 0 <= key <= 10^9
  • 0 <= value <= 10^9

More Bloomberg LP Phone Screen questions

  • Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
  • Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
  • Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • LRU CacheAthenahealth · PHONE SCREEN
  • LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
  • Balanced Session ManagerPalantir · PHONE SCREENPalantir interview questions
  • LRU CacheLotusFlare · ONSITE INTERVIEW
  • LRU CacheGimlet Labs · PHONE SCREEN
  • LRU CacheBNSF Railway · PHONE SCREENBNSF Railway interview questions
  • LRU CacheJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
  • LRU Cache OperationsHevo Data · ONSITE INTERVIEW

Interview reports that mention this question

  • Bloomberg SWE Intern Interview Questions: 68 Questions
  • Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
  • Bloomberg New Grad Question Bank: 161 Questions (Part 1 of 2)
  • Bloomberg New Grad Interviews: 2025 vs 2026 Guide
  • Bloomberg New Grad Screens: 30 Experiences (Part 4 of 5)
  • Bloomberg New Grad OOD Follow-ups: 14 Experiences (Part 3 of 5)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public int[] runLruCache(int capacity, String[] operations, int[][] arguments) {
        // write your code here
    }
}
Checking account…