dsa2 min read
4Sum II — Two-Map Split and Match
Count 4-tuples summing to zero by splitting into two pairs and using a frequency map of pair sums.
Read →
1575 articles
Count 4-tuples summing to zero by splitting into two pairs and using a frequency map of pair sums.
Implement an LFU cache with O(1) get/put using three hash maps: key→val, key→freq, freq→OrderedDict.
Design a data structure supporting inc/dec and getMaxKey/getMinKey in O(1) using a doubly linked list of frequency buckets.
Design Twitter with follow/unfollow and getNewsFeed using per-user tweet lists and a min-heap merge.
Find all index pairs forming palindromes by checking prefix/suffix splits against a reverse-word map.