Design a thread-safe cache whose entries expire after a time to live (TTL).
The cache receives a clock function in its constructor. Calling clock returns the current logical time in milliseconds. The judge controls this clock, so you should not read the system clock or create background cleanup threads.
Implement these operations:
put(key, value, ttlMillis) inserts or replaces a key. Its expiry time is clock() + ttlMillis.get(key) returns the stored value when the key exists and has not expired. Otherwise, it removes an expired entry if necessary and returns -1.size() removes all expired entries and returns the number of live entries.An entry is expired when the current time is greater than or equal to its expiry time. All three methods may be called concurrently on the same cache instance.
The judge creates the cache, supplies the logical clock, and starts all worker threads. Your implementation should provide only the cache state and synchronization.
The judge also preloads the standard concurrency, callback, and collection APIs for each supported language. You do not need to add import, include, or using statements.
Input:
Output:
Explanation: The entry expires at logical time 100 + 50 = 150. It is live at time 149 and expired at time 150.
Input:
Output:
Explanation: Replacing key 7 installs both the new value and the new expiry time. The old expiry at time 15 must not remove the replacement.
0 <= key <= 1_000_0000 <= value <= 1_000_0001 <= ttlMillis <= 1_000_0001_000 entries are live at once.20_000 method calls are made.-1 is reserved to represent a cache miss.Input
time = 100 put(1, 42, 50) get(1) time = 149 get(1) time = 150 get(1)
Output
[42, 42, -1]
Run is a quick check against the first couple of scenarios, which is roughly what these examples describe. Submit puts your class under the full set, which stays hidden.

