Untitled
unknown
python
2 months ago
977 B
4
Indexable
Never
from collections import defaultdict def getUnexpiredTokens(time_to_live, queries): token_expiry = {} # Dictionary to store token expiration times token_count = defaultdict(int) # Dictionary to store the count of unexpired tokens at each current time results = [] for query in queries: query_parts = query.split() query_type = query_parts[0] current_time = int(query_parts[-1]) if query_type == "generate": token_id = query_parts[1] token_expiry[token_id] = current_time + time_to_live elif query_type == "renew": token_id = query_parts[1] if token_id in token_expiry and token_expiry[token_id] > current_time: token_expiry[token_id] = current_time + time_to_live elif query_type == "count": count = sum(1 for expiry_time in token_expiry.values() if expiry_time >= current_time) results.append(count) return results