Skip to content

Instantly share code, notes, and snippets.

@aroranubhav
aroranubhav / LruCache.kt
Created February 20, 2025 06:24
Design a data structure that follows the constraints of a Least Recently Used (LRU) cache
class LRUCache(private val capacity: Int) {
inner class Node(
val key: Int,
val value: Int,
var next: Node? = null,
var prev: Node? = null
)
private val cache = mutableMapOf<Int, Node>()