Microsoft software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
Top 5 Recently Asked System Design Questions - Microsoft These are the commonly asked system design questions from Microsoft interviews and some...
Input: Listcapacity_bytes. Keys are opaque, case-sensitive strings such as account/container/blob@version; values are strings. An entry costs exactly len(value.encode("utf-8")) bytes. Ignore key and bookkeeping memory when enforcing capacity.now_ms. Calls use globally nondecreasing timestamps. An entry written with TTL ttl_ms expires at now_ms + ttl_ms and is unavailable when now_ms >= expires_at. Logically remove all expired entries before executing each operation, including a rejected write.put inserts or replaces an entry and makes it most recently used. If the new payload alone exceeds capacity, return false without changing any unexpired entry or its recency. Otherwise, remove the previous version of that key, evict least-recently-used entries until the new value fits, insert it with a fresh TTL, and return true.get makes the entry most recently used but does not extend its TTL. A missing or expired key returns null. Expiration events from an earlier write must never remove a later replacement of the same key.invalidate removes a live entry and reports whether it existed. stats reports the number of live entries and their total payload bytes. Neither operation changes the recency of remaining entries.BlobMetadataCache(capacity_bytes: int) — construct an empty cache.put(key: str, value: str, ttl_ms: int, now_ms: int) -> bool — insert or replace a payload, possibly evicting LRU entries.get(key: str, now_ms: int) -> str | None — return a live payload and update its recency.invalidate(key: str, now_ms: int) -> bool — remove a live entry if present.stats(now_ms: int) -> dict[str, int] — return exactly {"entries": count, "bytes": payload_bytes}.cache = BlobMetadataCache(10)
cache.put("acct/logs/a@v1", "Hot", 10, 0)
cache.put("acct/logs/b@v1", "Cool", 20, 0)
cache.get("acct/logs/a@v1", 1)
cache.put("acct/logs/c@v1", "Cool", 20, 1)
cache.get("acct/logs/b@v1", 1)
cache.stats(1)
cache.get("acct/logs/a@v1", 10)
cache.stats(10)[true, true, "Hot", true, null, {"entries": 2, "bytes": 7}, null, {"entries": 1, "bytes": 4}]Hot costs 3 bytes and Cool costs 4. Reading a makes b least recently used. Inserting c would require 11 bytes, so b is evicted, leaving 7 bytes. At time 10, a expires exactly at its deadline; only c remains.Example 2:cache = BlobMetadataCache(5)
cache.put("acct/docs/a@v1", "é", 3, 0)
cache.put("acct/docs/a@v1", "123456", 100, 1)
cache.get("acct/docs/a@v1", 1)
cache.put("acct/docs/b@v1", "XYZ", 10, 1)
cache.stats(1)
cache.put("acct/docs/a@v1", "Q", 20, 2)
cache.get("acct/docs/a@v1", 3)
cache.invalidate("acct/docs/b@v1", 3)
cache.stats(3)
cache.get("acct/docs/a@v1", 22)[true, false, "é", true, {"entries": 2, "bytes": 5}, true, "Q", true, {"entries": 1, "bytes": 1}, null]é occupies 2 UTF-8 bytes. The 6-byte replacement is rejected, preserving the original value. Adding XYZ fills the 5-byte budget. Replacing é with Q reduces usage to 4 bytes and sets a new deadline of 22. The original deadline of 3 must not delete this replacement. Invalidating b leaves 1 byte, and a expires at time 22.Constraints0 <= capacity_bytes <= 100,000,000; at most 100,000 public method calls per instance.1 <= ttl_ms <= 10^12 and 0 <= now_ms <= 10^15. Method arguments satisfy these bounds, and timestamps never decrease.Twitter class that supports the following methods:postTweet(userId: int, tweetId: int) -> None: Record a new tweet.getNewsFeed(userId: int) -> List[int]: Retrieve the 10 most recent tweet IDs in the user's news feed.follow(followerId: int, followeeId: int) -> None: Allow a follower to follow a followee.unfollow(followerId: int, followeeId: int) -> None: Allow a follower to unfollow a followee.def postTweet(self, userId: int, tweetId: int) -> Nonedef getNewsFeed(self, userId: int) -> List[int]def follow(self, followerId: int, followeeId: int) -> Nonedef unfollow(self, followerId: int, followeeId: int) -> NoneExample 1:twitter = Twitter()twitter.postTweet(1, 5)twitter.getNewsFeed(1)[5]Example 2:twitter.follow(1, 2)twitter.postTweet(2, 6)twitter.getNewsFeed(1)[6, 5]Constraints:0 <= userId, followerId, followeeId, tweetId <= 10^410^4. At most 3 * 10^4 follow operations will occur.LRUCache class that supports get(key: int) -> int and put(key: int, value: int) -> None methods. The cache will have a limited capacity.def get(self, key: int) -> int: Returns the value of the key if present, otherwise -1.def put(self, key: int, value: int) -> None: Updates the value of the key or adds it if it's not already present. When the cache reaches its capacity, it invalidates the least recently used item before inserting a new item.Example 1:cache = LRUCache(2)cache.put(1, 1)cache.put(2, 2)cache.get(1)1Example 2:cache.put(2, 1)cache.put(2, 2)cache.get(2)2Constraints:capacity will be between 1 and 3000.key and value are integers within the range of a 32-bit signed integer.Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free