Freshworks: O(1) LFU cache with recency as the tie-breaker
Problem. Implement a least-frequently-used cache with get(key) and put(key, value). When the cache is full, evict the key with the lowest access count. If several keys tie on count, evict the least recently used one among them.
How it went. This was the DSA round for a Staff Engineer role. The candidate started with a hash map plus a doubly linked list, then moved to the O(1) design: one map from key to node, and one map from frequency to a doubly linked list of nodes.
Discussion points. How a read or write bumps a key's frequency, moving a node from one frequency list to the next, keeping a running minimum frequency so eviction stays constant time, how LFU and LRU combine for tie-breaking, and showing every operation is O(1).
Second question. Product of the array except self, taken from O(n²) brute force to prefix and suffix products. The candidate cleared this round but was rejected after a frontend fundamentals round that followed.
Comments 0
No comments yet. Ask the author something, or add what happened in your own round.