PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/NVIDIA

Design and implement an LRU cache

Last updated: Mar 29, 2026

Quick Overview

This question evaluates knowledge of data structures, algorithmic design, API design, and memory/resource management required to implement an efficient eviction-based cache (LRU) that supports constant-time operations.

  • medium
  • NVIDIA
  • Coding & Algorithms
  • Software Engineer

Design and implement an LRU cache

Company: NVIDIA

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem Design and implement an **LRU (Least Recently Used) Cache** that supports the following operations in **O(1)** average time: - `get(key)` → returns the value associated with `key` if present; otherwise returns a sentinel (e.g., `-1`). Accessing a key counts as making it **most recently used**. - `put(key, value)` → inserts or updates the value for `key`. If the cache exceeds its capacity, it must evict the **least recently used** item. ## Requirements - The prompt may describe data structures in C; you may implement in **C or C++** (clarify your choice). - Define the cache API (constructor/init, `get`, `put`, cleanup/free if needed). - Handle edge cases: - Updating an existing key - Capacity = 0 - Repeated `get` calls ## Input/Output (for testing) You may assume the interviewer will test by calling your API methods in sequence (typical library-design style), rather than via stdin/stdout.

Quick Answer: This question evaluates knowledge of data structures, algorithmic design, API design, and memory/resource management required to implement an efficient eviction-based cache (LRU) that supports constant-time operations.

Related Interview Questions

  • Return all file paths via DFS - NVIDIA (easy)
  • Implement a disk space manager with eviction - NVIDIA (medium)
  • Implement short algorithms on logs, grids, and strings - NVIDIA (hard)
  • Implement encode/decode for list of strings - NVIDIA (easy)
  • Solve small string and API tasks - NVIDIA (medium)
NVIDIA logo
NVIDIA
Feb 8, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
3
0
Loading...

Problem

Design and implement an LRU (Least Recently Used) Cache that supports the following operations in O(1) average time:

  • get(key) → returns the value associated with key if present; otherwise returns a sentinel (e.g., -1 ). Accessing a key counts as making it most recently used .
  • put(key, value) → inserts or updates the value for key . If the cache exceeds its capacity, it must evict the least recently used item.

Requirements

  • The prompt may describe data structures in C; you may implement in C or C++ (clarify your choice).
  • Define the cache API (constructor/init, get , put , cleanup/free if needed).
  • Handle edge cases:
    • Updating an existing key
    • Capacity = 0
    • Repeated get calls

Input/Output (for testing)

You may assume the interviewer will test by calling your API methods in sequence (typical library-design style), rather than via stdin/stdout.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

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