FastPrepExpiring Key Set
Problems/Expiring Key Set

Expiring Key Set

Amazon logoAmazon● HardNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Amazon Experience 86 describes a hard data structure task, from an onsite interview. You build an unlimited set whose entries disappear on their own at their expiry dates, and the solution uses a min-heap. The report does not give the method names or what refresh and remove do. We wrote those details ourselves, as a finite stream of operations. Our version is about 82% the same as the reported question.

Simulate a set of string keys over time. The aligned arrays describe operations in nondecreasing timestamp order:

  • add: insert or refresh keys[i]. It expires at timestamps[i] + ttl[i].
  • contains: append whether keys[i] is currently present.
  • remove: delete keys[i] immediately if present.

At the start of every operation, delete entries whose expiration time is less than or equal to the current timestamp. For non-add operations, ttl[i] is zero. Return the answers to contains operations in encounter order.

Function

runExpiringSet(operations: String[], keys: String[], timestamps: int[], ttl: int[]) → boolean[]

Examples

Example 1

operations = ["add","contains","contains"]keys = ["a","a","a"]timestamps = [0,4,5]ttl = [5,0,0]return = [true,false]

The key is present before time 5 and absent exactly at its expiration time.

Example 2

operations = ["add","add","contains","contains"]keys = ["job","job","job","job"]timestamps = [0,2,3,7]ttl = [3,5,0,0]return = [true,false]

Refreshing at time 2 replaces expiration 3 with expiration 7.

Example 3

operations = ["add","contains","remove","contains"]keys = ["x","x","x","x"]timestamps = [1,2,3,3]ttl = [10,0,0,0]return = [true,false]

Removal takes effect for a later operation at the same timestamp.

Constraints

  • 1 <= operations.length = keys.length = timestamps.length = ttl.length <= 100000.
  • Operations are add, contains, or remove.
  • Keys are nonempty alphanumeric strings of length at most 40.
  • 0 <= timestamps[i] <= 2 * 10^9 and timestamps are nondecreasing.
  • For add, 1 <= ttl[i] <= 10^9; otherwise ttl[i] == 0.

More Amazon Onsite Interview questions

  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Dungeon GameONSITE INTERVIEW · Seen Nov 2026
  • Integer BreakONSITE INTERVIEW · Seen Nov 2026
  • LFU CacheONSITE INTERVIEW · Seen Nov 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • LRU Cache with TTLAutodesk · ONSITE INTERVIEWAutodesk interview questions
  • Tiered Expiring Item StoreHudson River Trading · PHONE SCREEN · ONSITE INTERVIEWHudson River Trading interview questions
  • Design Authentication ManagerOracle · ONSITE INTERVIEWOracle interview questions
  • Thread-Safe Task Storage and Worker DispatchNuro · ONSITE INTERVIEWNuro interview questions
  • Notification Deduplication WindowGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Helpdesk Ticket ProcessingThe Walt Disney Company · ONSITE INTERVIEWThe Walt Disney Company interview questions
  • Execute Tasks by PrioritySnowflake · ONSITE INTERVIEWSnowflake interview questions
  • Priority Job Scheduler with CooldownsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Progressive Banking SystemAirbnb · OAAirbnb interview questions

Amazon interview experiences

  • Amazon SWE OA with AI Coding: 1 Experience
  • Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
  • Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
  • Amazon BIE Intern SQL and Interview Questions: 17 Experiences
  • Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
  • Amazon SDE II (L5) Interview Questions: 5 Experiences
See Amazon hiring insights
Saved
class Solution {
    public boolean[] runExpiringSet(String[] operations, String[] keys, int[] timestamps, int[] ttl) {
      // write your code here
    }
}
Checking account…