PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency in designing and implementing efficient data structures (a fixed-capacity LRU key-value cache) and interval-processing algorithms (merging overlapping closed intervals), emphasizing time-complexity constraints, correct state management, and robustness to edge cases within the Coding & Algorithms category.

  • medium
  • Microsoft
  • Coding & Algorithms
  • Machine Learning Engineer

Implement cache and merge intervals

Company: Microsoft

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

The interview included two coding tasks: 1. Implement a fixed-capacity key-value cache with `get(key)` and `put(key, value)`. Both operations must run in O(1) average time. When the cache is full and a new key is inserted, evict the least recently used entry. A successful `get` also counts as a use. 2. Given a list of closed intervals `[start, end]`, merge all overlapping intervals and return the resulting non-overlapping intervals sorted by start value.

Quick Answer: This question evaluates proficiency in designing and implementing efficient data structures (a fixed-capacity LRU key-value cache) and interval-processing algorithms (merging overlapping closed intervals), emphasizing time-complexity constraints, correct state management, and robustness to edge cases within the Coding & Algorithms category.

LRU Cache Operation Simulation

Simulate a fixed-capacity LRU cache. Return outputs for each operation, with None for put.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: (2, [['put',1,1],['put',2,2],['get',1],['put',3,3],['get',2],['get',3]])

Expected Output: [None, None, 1, None, -1, 3]

Explanation: Evict least recently used key.

Input: (1, [['put',1,1],['put',1,2],['get',1]])

Expected Output: [None, None, 2]

Explanation: Updating key refreshes it.

Hints

  1. Model object-style prompts as operation streams when needed.
  2. Handle empty and boundary cases before the main logic.

Merge Closed Intervals

Merge overlapping closed intervals and return them sorted by start.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ([[1,3],[2,6],[8,10],[15,18]],)

Expected Output: [[1, 6], [8, 10], [15, 18]]

Explanation: Prompt example.

Input: ([[1,4],[4,5]],)

Expected Output: [[1, 5]]

Explanation: Closed intervals touching overlap.

Input: ([],)

Expected Output: []

Explanation: No intervals.

Hints

  1. Model object-style prompts as operation streams when needed.
  2. Handle empty and boundary cases before the main logic.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Return Top K Open Businesses - Microsoft (hard)
  • Implement Memory Allocation and In-Memory Records - Microsoft (medium)
  • Sort Three Categories In Place - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Retain Top K Elements - Microsoft (medium)