Solve Cache, Window, and Heap Problems
LinkedInSoftware Engineer · OnsiteLast updated
This question evaluates competency in advanced data structures and algorithmic techniques—specifically frequency-based cache design, sliding-window substring search, and heap-driven k-pair generation—along with time and space complexity analysis and robust edge-case handling.
You may be asked to solve multiple algorithmic problems in coding rounds:
-
Frequency-based cache: Implement a cache with
get(key)andput(key, value)inO(1)average time. When the cache is full, evict the key with the lowest access frequency. If multiple keys have the same frequency, evict the least recently used among them. -
Shortest covering substring: Given two strings
sandt, return the shortest contiguous substring ofsthat contains every character intwith the required multiplicities. If no such substring exists, return an empty string. -
Smallest-sum pair generation: Given two non-decreasing integer arrays
nums1andnums2, and an integerk, return thekpairs(nums1[i], nums2[j])with the smallest sums. If fewer thankpairs exist, return all possible pairs.
Discuss the expected time and space complexity for each problem and handle edge cases such as duplicates, empty input, and large k.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.