PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/XPeng

Build a Least-Recently-Used Store

Last updated: May 5, 2026

Quick Overview

This question evaluates understanding of caching and eviction policies and practical proficiency with data structures such as hash tables and ordered collections for tracking and updating recency.

  • medium
  • XPeng
  • Coding & Algorithms
  • Data Engineer

Build a Least-Recently-Used Store

Company: XPeng

Role: Data Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Implement an in-memory key-value store with least-recently-used eviction. The store is initialized with a positive integer `capacity` and supports two operations: - `get(key)`: Return the value associated with `key` if it exists; otherwise return `-1`. Accessing a key makes it the most recently used key. - `put(key, value)`: Insert or update `key` with `value`. Updating an existing key also makes it the most recently used key. If inserting a new key causes the number of keys to exceed `capacity`, evict the least recently used key. For this interview variant, you do not need to use a linked list. An implementation based on a hash map plus a dynamic array/list is acceptable, even if moving keys in the list costs linear time. Example: ```text store = Store(capacity = 2) put(1, 10) put(2, 20) get(1) -> 10 # key 1 becomes most recently used put(3, 30) # evicts key 2 get(2) -> -1 get(3) -> 30 put(1, 15) # updates key 1 and makes it most recently used get(1) -> 15 ```

Quick Answer: This question evaluates understanding of caching and eviction policies and practical proficiency with data structures such as hash tables and ordered collections for tracking and updating recency.

Related Interview Questions

  • Compute optimal matrix multiplication order - XPeng (Medium)
XPeng logo
XPeng
Apr 11, 2026, 12:00 AM
Data Engineer
Technical Screen
Coding & Algorithms
0
0

Implement an in-memory key-value store with least-recently-used eviction.

The store is initialized with a positive integer capacity and supports two operations:

  • get(key) : Return the value associated with key if it exists; otherwise return -1 . Accessing a key makes it the most recently used key.
  • put(key, value) : Insert or update key with value . Updating an existing key also makes it the most recently used key. If inserting a new key causes the number of keys to exceed capacity , evict the least recently used key.

For this interview variant, you do not need to use a linked list. An implementation based on a hash map plus a dynamic array/list is acceptable, even if moving keys in the list costs linear time.

Example:

store = Store(capacity = 2)
put(1, 10)
put(2, 20)
get(1)      -> 10   # key 1 becomes most recently used
put(3, 30)          # evicts key 2
get(2)      -> -1
get(3)      -> 30
put(1, 15)          # updates key 1 and makes it most recently used
get(1)      -> 15

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More XPeng•More Data Engineer•XPeng Data Engineer•XPeng Coding & Algorithms•Data 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.