PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW
|Home/Coding & Algorithms/Shopify

Implement a Capacity-Bounded Cache

Last updated: Apr 6, 2026

Quick Overview

This question evaluates a candidate's ability to design and implement an efficient capacity-bounded in-memory key-value cache, assessing understanding of performance constraints such as average-case constant-time get/put operations and eviction behavior.

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

Implement a Capacity-Bounded Cache

Company: Shopify

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Implement an in-memory key-value cache with a fixed capacity. The cache must support the following operations in constant time on average: - `get(key)`: Return the value associated with `key` if it exists; otherwise return `-1`. - `put(key, value)`: Insert or update the value for `key`. If inserting a new key would exceed the cache capacity, evict the item that has been unused for the longest time. Accessing or updating a key makes it the most recently used item. You should be prepared to explain the underlying data structures, especially how a hash map and a doubly linked list can be combined to support both fast lookup and fast eviction.

Quick Answer: This question evaluates a candidate's ability to design and implement an efficient capacity-bounded in-memory key-value cache, assessing understanding of performance constraints such as average-case constant-time get/put operations and eviction behavior.

Related Interview Questions

  • Compute Jaccard Similarity for Lists - Shopify (medium)
  • Implement URL Shortening Codec - Shopify (medium)
  • Simulate a rover fleet - Shopify (medium)
  • Simulate robot moves on a grid - Shopify (medium)
  • Simulate rover movement on a grid - Shopify (easy)
Shopify logo
Shopify
Feb 3, 2026, 12:00 AM
Machine Learning Engineer
Technical Screen
Coding & Algorithms
2
0
Loading...

Implement an in-memory key-value cache with a fixed capacity. The cache must support the following operations in constant time on average:

  • get(key) : Return the value associated with key if it exists; otherwise return -1 .
  • put(key, value) : Insert or update the value for key . If inserting a new key would exceed the cache capacity, evict the item that has been unused for the longest time.

Accessing or updating a key makes it the most recently used item.

You should be prepared to explain the underlying data structures, especially how a hash map and a doubly linked list can be combined to support both fast lookup and fast eviction.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Shopify•More Machine Learning Engineer•Shopify Machine Learning Engineer•Shopify Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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.