You are given two separate coding tasks.
Implement an in-memory cache with a fixed capacity that evicts the least recently used (LRU) key when the capacity is exceeded.
Implement the following operations:
get(key)
: return the value associated with
key
if present; otherwise return -1.
put(key, value)
: insert or update the value for
key
. If the cache exceeds its capacity after this operation, evict the least recently used key.
Both operations must run in average O(1) time.
Assume keys and values are integers. The cache capacity is a positive integer given at construction time.
You are given an array primes of distinct prime integers, length n where 1 <= n <= 15 and each value is in the range [2, 10^6].
Return a sorted list (ascending order) containing all unique products that can be formed by taking the product of any non-empty subset of primes. Each prime can be used at most once in a product (that is, you are considering subsets, not multisets).
Example:
primes = [2, 3, 11]
[2]
-> 2
[3]
-> 3
[11]
-> 11
[2, 3]
-> 6
[2, 11]
-> 22
[3, 11]
-> 33
[2, 3, 11]
-> 66
[2, 3, 6, 11, 22, 33, 66]