Grok 4.1 Fast· xai
Frontier Reasoning Traces
Build a caching system with LFU (Least Frequently Used) eviction policy.
- User
Build a caching system with LFU (Least Frequently Used) eviction policy.
- Assistantpython
from collections import OrderedDict class LFUCache: def __init__(self, capacity: int): self.capacity = capacity self.val = {} self.freq = {} self.order = {} self.size = 0 self.min_freq = 1 def _update_min_freq(self): while True: if self.min_freq not in self.order or len(self.order[self.min_freq]) == 0: self.min_freq += 1 else: break def _increase_freq(self, key: int): old_freq = self.freq[key] del self.order[old_freq][key] self.freq[key] += 1 new_freq = self.freq[key] if new_freq not in self.order:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.