Solve Throughput, Rate Limiting, and LFU
Company: Microsoft
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
The interview included the following coding tasks:
1. **Minimum processing speed**: You are given an array `piles`, where `piles[i]` is the size of the `i`th pile, and an integer `h`. In one hour, you may choose exactly one pile and process up to `k` items from it. If a pile has fewer than `k` items remaining, you finish it and the rest of that hour is unused. Return the minimum integer `k` such that all piles can be finished within `h` hours.
2. **Implement a rate limiter**: Design and implement a rate limiter that enforces a rule such as allowing at most `limit` requests per user within any rolling `windowSeconds` interval. Provide an API like `allow(userId, timestamp) -> bool`. Explain how you store request history, how expired requests are removed efficiently, and what the time and space complexity is.
3. **Implement an LFU eviction structure**: Design a key-value cache with a fixed capacity. Support `get(key)` and `put(key, value)` in O(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.
Quick Answer: This set of tasks evaluates algorithmic problem-solving, data structure design, and systems-oriented reasoning by testing throughput calculation, rolling-window rate limiting, and LFU cache eviction with O(1) access constraints.