LRU Cache Simulation

Medium Mini Projects & Algorithmic Challenges
Solve in Playground →

Problem Statement

Write a C++ program simulating a basic fixed-capacity Least Recently Used (LRU) cache queue insertion log.

Input Format

Capacity K followed by N page reference requests.

Output Format

Print final cache contents in order.

Constraints

1 <= K <= 5, 1 <= N <= 20

Sample Input

2 4
1 2 1 3

Sample Output

1 3

Explanation

Evicts least recently referenced elements upon capacity overflow.

Starter Code

#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    int cap, n;
    if (std::cin >> cap >> n) {
        // Write your LRU cache logic here
    }
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used