Skip to content
Zeni Study
  • Pages
    • Learn Python In 7 Days
      • Day 1 : Variable + if/else
      • Day 2: Loops
      • Day 3 : Array + String
      • Day 4 — Functions
      • Day 5 — Dictionaries - Hashmap
      • Day 6 — Files & Errors
      • Day 7 — Mini Project & Programmer Thinking
    • Machine Coding:
      • Day 1 — Bank account + Wallet :
      • Day 2 : RateLimiter + seat booking
      • Day 3 : Library Management + Classroom Attendance System
      • Day 4 : Bank account and notification system.
      • Day 5 : Key-value and payment processor.
      • Day 6 : Discount engine + Seat booking( in depth)
      • Day 7: Parking lot System :
    • Machine coding extended:
      • Day 7.5 — Parking Lot (Constraint-Heavy Variant)
      • Day 8 : Order + Payment System
      • Day 8 — Extension Round (Mid-Interview Change)
      • Day 9 — Ticket Booking with Expiry (Simulated Time)
      • Day 9 — Extension Round (Seat Lock Ownership + Forced Unlock)
    • SQL + DB Thinking course
      • Day 1 — Tables, Rows & Thinking in Data
      • Day 2 — Relationships & Foreign Keys (Thinking in Connections)
      • Day 3 — Filtering, Aggregation & Answering Data Questions
      • Day 4 — JOINs (Combining Tables the Right Way)
      • Day 5 — Subqueries, EXISTS & NOT EXISTS (Thinking in Layers)
      • Day 6 — Indexes, Constraints & How Databases Think
      • Day 7 — Full SQL Interview Simulation (SDE-1 Ready)
      • Extended Day 1 — Core Business Systems (Deep Practice)
      • Extended Day 2 — Booking & Platform Systems (High-Depth Practice)
      • Extended Day 3 — Content & Learning Platforms (Capstone Practice)
    • LLD: Java
      • icon picker
        DAY 1 — Core Foundations (SDE-2 Level)
      • DAY 2 — State, Time & Domain Correctness
      • DAY 3 — Extensibility & Failure Handling (SDE-2 Core Signal)
      • DAY 4 — Concurrency, Scheduling & Consistency (SDE-2 Critical)
      • DAY 5 — Workflow Design & Config-Driven Systems (SDE-2+)
      • DAY 6 — Eventing & Usage-Based Systems (Advanced SDE-2)
      • DAY 7 — Interview Simulation (Hard, Production-Grade)
      • Hidden Edge Cases Interviewers Expect (Day-wise)
      • Detailed Testing file:
    • Assignment:
      • If else Practice Set

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

Correct sliding window logic
Synchronization strategy
Clean data structures
No memory leaks

✅ 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:
Store value + expiryTime
On get, check expiry
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)

Java91 lines

🎯 What Interviewer Evaluates

Expiry correctness
Clean modeling
Edge-case handling
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;


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