Question
Implement an LFU (least-frequently-used) cache with the given capacity, then replay a list of operations against it. Each operation is one of ["put", key, value] or ["get", key]. On get, return the cached value or -1 and bump the key's frequency. On put, insert/update the value (bumping frequency); if at capacity, evict the least-frequently-used key first, breaking ties by least-recently-used. All operations must be O(1) amortized. Return the list of results from every get operation, in order. Capacity is between 0 and 10^4; at most 10^5 operations.
lfu_cache(capacity: int, ops: list[list]) → list[int][2,[["put",1,1],["put",2,2],["get",1],["put",3,3],["get",2],["get",3],["put",4,4],["get",1],["get",3],["get",4]]]out[1,-1,3,-1,3,4]State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.