Expiring Key Set
Updated
Problem statement
Simulate a set of string keys over time. The aligned arrays describe operations in nondecreasing timestamp order:
add: insert or refreshkeys[i]. It expires attimestamps[i] + ttl[i].contains: append whetherkeys[i]is currently present.remove: deletekeys[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, orremove. - Keys are nonempty alphanumeric strings of length at most
40. 0 <= timestamps[i] <= 2 * 10^9and timestamps are nondecreasing.- For add,
1 <= ttl[i] <= 10^9; otherwisettl[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