FastPrepRank-Based Cache with a Data Source
Problems/Rank-Based Cache with a Data Source

Rank-Based Cache with a Data Source

LinkedIn logoLinkedIn● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a LinkedIn phone screen. The report describes a cache that reads from a data source on a miss. When it is full, it evicts by rank, and get must be thread-safe. Here, the records are fixed integers and requests happen one at a time. We chose to evict an existing entry before adding a new one, to break ties by key, what happens at capacity zero, the limits, and a trace of how many reads happen. The original get returns only the value. Our version is about 85% the same as the reported question.

Implement a fixed-capacity cache backed by a data source. Each input row [key, value, rank] describes one data-source record that does not change. All keys are unique, every requested key exists in the data source, and values and ranks remain fixed during this batch. The cache begins empty.

Process the requested keys in order. For each get(key):

  • If the key is cached, return its cached value without reading the data source.
  • Otherwise read its record from the data source and add one to the total number of data-source reads.
  • If capacity is positive, store the missed record. When already full, first evict the existing cached record with the smallest rank, breaking ties by the smallest key. Then insert the newly fetched record, even if its rank is lower than the evicted rank.
  • Capacity zero stores no records.

The function returns one string "value backendReads" per request. Its first number is the value returned by get; its second is a cumulative read counter starting at zero for this cache instance, included to make hits and eviction behavior observable.

Each get is atomic in the supplied order, which represents one valid order in which concurrent calls could complete atomically. In a shared concurrent class, protect the complete hit-or-fetch, counter update, eviction and insertion as one operation. Cache hits do not change ranks or eviction order.

Function

runRankCache(capacity: int, records: int[][], requests: int[]) → String[]

Examples

Example 1

capacity = 2records = [[1,10,5],[2,20,2],[3,30,9]]requests = [1,2,1,3,2]return = ["10 1","20 2","10 2","30 3","20 4"]

The second number is the cumulative number of data-source reads. Hits return the cached value without increasing it; misses read and then store when capacity permits.

Example 2

capacity = 1records = [[1,7,100],[2,8,1]]requests = [1,2,1]return = ["7 1","8 2","7 3"]

The second number is the cumulative number of data-source reads. Hits return the cached value without increasing it; misses read and then store when capacity permits.

Example 3

capacity = 0records = [[5,9,4]]requests = [5,5]return = ["9 1","9 2"]

The second number is the cumulative number of data-source reads. Hits return the cached value without increasing it; misses read and then store when capacity permits.

Constraints

  • 0 <= capacity <= 100000.
  • 0 <= records.length, requests.length <= 100000.
  • Every record has exactly three integers, keys are unique, and every request names a supplied key.
  • -10^9 <= key, value, rank <= 10^9.
  • The data source always succeeds, and its values and ranks are immutable for this batch.

More LinkedIn Phone Screen questions

  • Maximum Product of a Contiguous SubarrayPHONE SCREEN · Seen Nov 2026
  • Maximum Sum of a Contiguous SubarrayPHONE SCREEN · Seen Nov 2026
  • Merge Two Sorted ListsPHONE SCREEN · Seen Nov 2026
  • Sqrt(x)PHONE SCREEN · Seen Nov 2026
  • Total Years of Work ExperiencePHONE SCREEN · Seen Nov 2026
  • Sum an Arbitrary-Dimensional ArrayPHONE SCREEN · Seen Oct 2026
  • Known Words Matching Phone DigitsPHONE SCREEN · Seen Oct 2026
  • Inverse-Depth Nested List SumPHONE SCREEN · Seen Oct 2026
  • Valid Number with ExponentsPHONE SCREEN · Seen Oct 2026
  • Sort a Quadratic-Transformed ArrayPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Thread-Safe Task Storage and Worker DispatchNuro · ONSITE INTERVIEWNuro interview questions
  • Paged KV Cache AccessNVIDIA · PHONE SCREENNVIDIA interview questions
  • Balanced Session ManagerPalantir · PHONE SCREENPalantir interview questions
  • Worst-Performing Ads by CTR in a Campaign TreeUber · PHONE SCREENUber interview questions
  • Timer Job Scheduler Wake-upsRedNote · PHONE SCREEN
  • In-Memory Priority Task SchedulerRippling · PHONE SCREENRippling interview questions
  • Design a Food Rating SystemApple · PHONE SCREENApple interview questions
  • Key-Value Store on a Block DeviceLambda · PHONE SCREEN
  • Mutable Stock Price Top KBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Order Book with Cancel by Order IDCitadel · PHONE SCREENCitadel interview questions

LinkedIn interview experiences

  • LinkedIn Senior MLE Interview Questions: 1 Experience
  • LinkedIn Staff AI Engineer Phone Screens: 1 Experience
  • LinkedIn Experienced MLE Onsite: 1 Experience
  • LinkedIn Coding with AI Interview: 4 Experiences
  • LinkedIn Experienced Infrastructure SWE Onsite: 1 Experience
All LinkedIn interview questionsSee LinkedIn hiring insights
Saved
class Solution {
    public String[] runRankCache(int capacity, int[][] records, int[] requests) {
        // Write your code here.
    }
}
Checking account…