PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Pinduoduo

Design a Recency-Eviction Cache

Last updated: Apr 6, 2026

Quick Overview

This question evaluates proficiency with data structures and algorithmic design for implementing a fixed-capacity key-value cache that enforces recency-based eviction while meeting average O(1) get and put performance.

  • medium
  • Pinduoduo
  • Coding & Algorithms
  • Software Engineer

Design a Recency-Eviction Cache

Company: Pinduoduo

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Implement a fixed-capacity key-value cache that removes the least recently used entry when it becomes full. Support the following operations: - `get(key)`: Return the value associated with `key` if it exists; otherwise return `-1`. Accessing a key marks it as recently used. - `put(key, value)`: Insert or update the value for `key`. If the cache is already at capacity and the key does not exist, evict the least recently used key before inserting the new one. Updating an existing key should also mark it as recently used. Requirements: - Cache capacity is a positive integer provided at initialization. - Both `get` and `put` should run in average `O(1)` time. - You may assume keys are unique integers and values are integers. Example: - Capacity = 2 - `put(1, 10)` - `put(2, 20)` - `get(1)` returns `10` - `put(3, 30)` evicts key `2` - `get(2)` returns `-1` - `put(4, 40)` evicts key `1` - `get(1)` returns `-1` - `get(3)` returns `30` - `get(4)` returns `40`

Quick Answer: This question evaluates proficiency with data structures and algorithmic design for implementing a fixed-capacity key-value cache that enforces recency-based eviction while meeting average O(1) get and put performance.

Related Interview Questions

  • Find Shortest Square-Sum Path - Pinduoduo (hard)
  • Compute User Login Streaks - Pinduoduo (easy)
  • Determine Straight Flush - Pinduoduo (easy)
  • Find missing rank in a straight - Pinduoduo (easy)
  • Find next greater element for subset - Pinduoduo (easy)
Pinduoduo logo
Pinduoduo
Feb 21, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
3
0
Loading...

Implement a fixed-capacity key-value cache that removes the least recently used entry when it becomes full.

Support the following operations:

  • get(key) : Return the value associated with key if it exists; otherwise return -1 . Accessing a key marks it as recently used.
  • put(key, value) : Insert or update the value for key . If the cache is already at capacity and the key does not exist, evict the least recently used key before inserting the new one. Updating an existing key should also mark it as recently used.

Requirements:

  • Cache capacity is a positive integer provided at initialization.
  • Both get and put should run in average O(1) time.
  • You may assume keys are unique integers and values are integers.

Example:

  • Capacity = 2
  • put(1, 10)
  • put(2, 20)
  • get(1) returns 10
  • put(3, 30) evicts key 2
  • get(2) returns -1
  • put(4, 40) evicts key 1
  • get(1) returns -1
  • get(3) returns 30
  • get(4) returns 40

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Pinduoduo•More Software Engineer•Pinduoduo Software Engineer•Pinduoduo Coding & Algorithms•Software Engineer Coding & Algorithms
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.