FastPrepPriority, Expiration, and LRU Eviction
Problems/Priority, Expiration, and LRU Eviction

Priority, Expiration, and LRU Eviction

Tesla logoTesla● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Tesla SWE phone screen. The report says how expiration, priority, and LRU rank against each other. It does not give a cache API or the final tie rule. Our version asks which item to evict, and it is about 85% the same as the reported question.

A cache currently contains n items. Item i has key keys[i], priority priorities[i], expiration time expirations[i], and last-used time lastUsed[i].

Select the key of the one item to evict at time now using this precedence:

  1. If at least one item is expired, only expired items are eligible. An item is expired when expirations[i] <= now. Return the smallest eligible key.
  2. Otherwise, keep only items with the smallest priority value.
  3. If several items have that priority, choose the least recently used one: the item with the smallest lastUsed value.
  4. If a tie still remains, return the smallest key.

Function

selectEvictionKey(keys: int[], priorities: int[], expirations: int[], lastUsed: int[], now: int) → int

Examples

Example 1

keys = [10,20,30]priorities = [5,1,1]expirations = [100,40,40]lastUsed = [9,8,7]now = 50return = 20

Keys 20 and 30 are expired. Expiration takes precedence over priority and recency, and the smaller eligible key is 20.

Example 2

keys = [1,2,3,4]priorities = [2,1,1,3]expirations = [100,100,100,100]lastUsed = [5,8,3,1]now = 50return = 3

No item is expired. Keys 2 and 3 have the minimum priority, and key 3 has the earlier last-used time.

Example 3

keys = [9,4]priorities = [1,1]expirations = [100,100]lastUsed = [7,7]now = 50return = 4

The items tie on expiration status, priority, and recency, so the smaller key is returned.

Constraints

  • 1 <= n <= 10^5.
  • All four arrays have length n.
  • All keys are distinct.
  • 0 <= keys[i], priorities[i], expirations[i], lastUsed[i], now <= 10^9.
  • Smaller lastUsed values represent less recent access.

More Tesla Phone Screen questions

  • Flatten a Branched List into a Doubly Linked ListPHONE SCREEN · Seen Sep 2026
  • Reduce-Based Map and Filter PipelinePHONE SCREEN · Seen Sep 2026
  • Resilient Fake API ClientPHONE SCREEN · Seen Sep 2026
  • Merge JSON Array FieldsPHONE SCREEN · Seen Aug 2026
  • KV Store with RollbackPHONE SCREEN · Seen Apr 2026
  • Multi-Channel Valid ConvolutionPHONE SCREEN · Seen Oct 2024
  • Course Schedule FeasibilityPHONE SCREEN · Seen Aug 2024
  • Average of a Fixed-Size ArrayPHONE SCREEN · Seen Jun 2024
  • Swap Even and Odd BitsPHONE SCREEN · Seen Mar 2023
  • Find the Intersection Node of Two Linked ListsPHONE SCREEN · Seen Oct 2022

Similar questions at other companies

  • Climb Detection with Recoverable DipsStrava · PHONE SCREEN
  • Evenly Schedule Vehicle InspectionsAmazon · PHONE SCREEN
  • Experiment Bucket Allocation and RebalancingPinterest · PHONE SCREENPinterest interview questions
  • Automation Pipeline, Part 3: Stage DurationPlaid · PHONE SCREENPlaid interview questions
  • Generate an Optimal Portfolio Trading ReportPoint72 · PHONE SCREENPoint72 interview questions
  • Future-Aware Cache EvictionBenchling · PHONE SCREENBenchling interview questions
  • Conveyor Triplet PackagingGoogle · PHONE SCREENGoogle interview questions
  • Maximize Circular Rover TravelBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Text JustificationUber · PHONE SCREENUber interview questions
  • Find GPU Capacity and Drain a NodeTogether AI · PHONE SCREEN

Interview reports that mention this question

  • Tesla Older SWE Intern Reports: 14 Experiences (Part 4 of 4)
  • Tesla Intern Python Interview Prep Guide
  • Tesla SWE Intern Interviews: 50 Experiences (Part 1 of 4)

Tesla interview experiences

  • Tesla Experienced Infrastructure SWE Interviews: 1 Experience
  • Tesla Embedded and SRE Intern Loops: 15 Experiences (Part 3 of 4)
  • Tesla SWE and Data Intern Rounds: 10 Experiences (Part 2 of 4)
All Tesla interview questionsSee Tesla hiring insights
Saved
class Solution {
    public int selectEvictionKey(int[] keys, int[] priorities, int[] expirations, int[] lastUsed, int now) {
      // write your code here
    }
}
Checking account…