Skip to content

DAY 1 — Core Foundations (SDE-2 Level)


🟢 DAY 1 — Core Foundations (SDE-2 Level)

Concepts Introduced Today

You’ll practice:
Time-based logic
Thread safety
Clear API design
Edge-case driven coding
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 windowSizelimit
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:
Time handling
Removing expired entries
Thread safety

📌 Problem Statement

Design an in-memory rate limiter.

Requirements

Per-user rate limiting
Sliding window algorithm
Thread-safe
Millisecond precision

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)

Java93 lines

🎯 What Interviewer Evaluates

 
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.