🟢 DAY 1 — Core Foundations (SDE-2 Level)
Concepts Introduced Today
You’ll practice:
No advanced patterns yet — focus is correctness + clarity.
✅ Problem 1: Rate Limiter (Sliding Window, Single Node)
🔹 New Concept (Short Explanation)
Sliding Window Rate Limiter
Instead of fixed buckets:
Track timestamps of requests Allow request if count in last windowSize ≤ limit Example:
Limit = 3 requests / 10 seconds
Requests at times:
t=1 -> allowed
t=2 -> allowed
t=3 -> allowed
t=9 -> ❌ blocked (3 already in window)
t=11 -> allowed (t=1 expired)
Key challenges:
📌 Problem Statement
Design an in-memory rate limiter.
Requirements
Example
limit = 2 requests / 5 seconds
request("user1") -> true
request("user1") -> true
request("user1") -> false
(wait 5 seconds)
request("user1") -> true
🧩 Java Interface (DO NOT MODIFY)
public interface RateLimiter {
boolean allowRequest(String userId);
}
🧪 Driver Code (Auto Tests + Edge Cases)
🎯 What Interviewer Evaluates
Correct sliding window logic ✅ Problem 2: In-Memory Key Value Store with TTL
🔹 New Concept (Short Explanation)
TTL (Time To Live)
Each key expires after a given duration.
Approach:
No background cleanup (lazy deletion) 📌 Problem Statement
Design an in-memory key-value store with TTL support.
Operations
put(key, value, ttlMillis)
get(key) -> value or null
Example
put("a", "1", 2000)
get("a") -> "1"
(wait 2 seconds)
get("a") -> null
🧩 Java Interface (DO NOT MODIFY)
public interface KeyValueStore {
void put(String key, String value, long ttlMillis);
String get(String key);
}
🧪 Driver Code (Auto Tests + Edge Cases)
🎯 What Interviewer Evaluates
Simplicity over overengineering 🧠 Day 1 Takeaways
By end of Day 1, you should be comfortable with:
Translating requirements → code Handling time-based logic Writing test-passing, interview-ready Java
Solution:
Problem 1:
package day1P1;
import java.time.Instant;
import java.util.ArrayDeque;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;