Blind 75: Day 55/75
Problem: Find Median from Data Stream
LeetCode 295: https://t.co/4zC3ESIlSN
Design a data structure that supports adding integers from a data stream and finding the median of all elements added so far.
Implement two operations:
addNum(num): Add an integer to the data structure.
findMedian(): Return the median of all elements added so far.
You must make median retrieval efficient.
Example 1
Input:
["MedianFinder", "addNum", "addNum", "findMedian", "addNum", "findMedian"]
[[], [1], [2], [], [3], []]
Output:
[null, null, null, 1.5, null, 2.0]
Explanation:
After adding 1 and 2:
Median = (1 + 2) / 2 = 1.5
After adding 3:
Median = 2
Example 2
Input:
["MedianFinder", "addNum", "findMedian", "addNum", "findMedian"]
[[], [2], [], [3], []]
Output:
[null, null, 2.0, null, 2.5]
Approach: Two Heaps
Instead of sorting the entire collection every time we need the median, use two heaps to maintain the smaller and larger halves of the numbers.
Step 1: Initialize Two Heaps
Max Heap:
Stores the smaller half of the numbers.
Min Heap:
Stores the larger half of the numbers.
Step 2: Insert a Number
When a new number arrives:
→ Compare it with the maximum element of the max heap.
→ Insert it into the appropriate heap.
→ Maintain the ordering of both heaps.
Step 3: Balance the Heaps
Maintain these conditions:
→ The size difference between the two heaps should never exceed 1.
→ Every element in the max heap must be less than or equal to every element in the min heap.
Step 4: Find the Median
If both heaps contain the same number of elements:
Median = (https://t.co/zU3TvSmUZh() + https://t.co/eRS1HIVp45()) / 2.0
If one heap contains more elements:
Median = top element of the larger heap.
Key Observation
The median divides a sorted collection into two halves.
A Max Heap gives quick access to the largest element in the smaller half.
A Min Heap gives quick access to the smallest element in the larger half.
Together, they allow us to calculate the median without sorting the entire collection.
Complexity
Time:
addNum(): O(log n)
findMedian(): O(1)
Space: O(n)
FAANG Takeaway
Find Median from Data Stream demonstrates how two heaps can efficiently maintain order in a continuously changing dataset.
Instead of sorting after every insertion, maintain two balanced halves and access their boundary elements directly.
Remember:
Max Heap stores the smaller half. Min Heap stores the larger half. Their top elements determine the median.
Next: Day 56/75
There's nothing wrong with getting a job through your uncle, relatives, or family connections. That's how networking works, and there's no shame in having that advantage.
But don't turn it into a story about how you cracked the placement entirely on your own.
Getting the opportunity through a connection and earning your place through your work are two different things.
Be proud of your job, but be honest about how you got the opportunity.
LLD Interview Notes: Day 33/50
Topic: Proxy Pattern
The Proxy Pattern is a structural design pattern that provides a substitute object to control access to the actual object.
Key Concepts:
Controls access to objects.
Supports lazy initialization.
Enables security checks and authorization.
Supports caching, logging, and remote access.
Real-World Example: Document Access
Client → Document Proxy → Real Document
The proxy verifies user permissions before allowing access to the actual document.
Types of Proxy:
Virtual Proxy: Lazy loading.
Protection Proxy: Access control.
Remote Proxy: Remote object access.
Caching Proxy: Reuses stored results.
Logging Proxy: Records operations.
Proxy vs Decorator:
Proxy controls access to an object.
Decorator adds behavior to an object.
FAANG Takeaway
The Proxy Pattern adds a control layer between the client and the real object without changing the object's implementation.
Remember:
The client talks to the Proxy. The Proxy controls access to the Real Subject.
Next: Day 34/50
Bridge Pattern in LLD
Ultimate DSA Premium Kit 👇
Get the Ultimate DSA Premium Kit: https://t.co/g4E6x1XJPQ
Your complete system for coding interview preparation.
Most DSA resources give you a list of problems to solve.
But knowing what to solve, which pattern to apply, and how to approach an unfamiliar problem is what actually matters in interviews.
That's why I put together the Ultimate DSA Premium Kit.
What's included?
📚 Learning & Roadmap
→ Complete DSA roadmap
→ 30+ topic-wise DSA notes
→ Pattern recognition guide
→ Algorithm master sheet
→ DSA cheat sheets for quick revision
💻 Problem Solving & Practice
→ 150 interview-focused problems
→ Step-by-step solution playbook
→ LeetCode strategy and interview mode
→ Company-wise DSA preparation
📅 Planning & Tracking
→ 30 / 60 / 90-day study plans
→ Progress tracker and mistake log
→ Weekly review and mock interview tracker
→ Revision and mastery system
🎯 Additional Resources
→ Guide for getting unstuck on difficult problems
→ Curated YouTube, GitHub, and LeetCode resources
The goal isn't to solve 500 random problems.
It's to build a structured process around:
→ What to study
→ What to practice
→ Which pattern to recognise
→ How to approach a problem
→ How to identify your mistakes
→ What to revise next
Everything is organised in one place, so you spend less time searching for resources and more time preparing.
If you're preparing for SDE interviews and want a structured DSA preparation system, check it out.
Blind 75: Day 54/75
Problem: Sliding Window Maximum
LeetCode 239: https://t.co/t9a54PUgUz
Given an array of integers nums and an integer k, there is a sliding window of size k that moves from the left to the right of the array.
Return the maximum value in each window.
You must solve it in O(n) time.
Example 1
Input: nums = [1,3,-1,-3,5,3,6,7], k = 3
Output: [3,3,5,5,6,7]
Explanation:
The maximum values in each window are:
[1,3,-1] → 3
[3,-1,-3] → 3
[-1,-3,5] → 5
[-3,5,3] → 5
[5,3,6] → 6
[3,6,7] → 7
Example 2
Input: nums = [1], k = 1
Output: [1]
Approach: Sliding Window + Monotonic Deque
Checking every element in every window would take O(n × k) time.
Instead, use a deque to maintain useful candidates for the maximum.
The deque stores indices in decreasing order of their corresponding values.
Step 1: Initialize
Create a deque to store indices.
Create a result array.
Iterate through the array using right.
Step 2: Remove Out-of-Window Elements
If the front index is outside the current window:
Remove it from the deque.
Condition:
deque.front() <= right - k
Step 3: Maintain Decreasing Order
While the deque is not empty and:
nums[deque.back()] <= nums[right]
Remove the back element.
Why?
The current element is larger, so the smaller element can never become the maximum while the current element remains in the window.
Step 4: Add the Current Index
Push right into the deque.
The front of the deque now represents the maximum element's index.
Step 5: Store the Maximum
Once the first complete window is formed (right >= k - 1):
Add nums[deque.front()] to the result.
Key Observation
The deque maintains indices of potential maximum elements in decreasing order of their values.
Smaller elements are removed when a larger element arrives because they can no longer become the maximum before leaving the window.
Complexity
Time: O(n)
Space: O(k)
Each index is inserted and removed at most once.
FAANG Takeaway
Sliding Window Maximum demonstrates how a Monotonic Deque can optimize a sliding window problem.
Instead of recalculating the maximum for every window, maintain only the elements that can still become the maximum.
Remember:
Keep the deque decreasing. Remove expired indices. The front always gives the maximum.
Next: Day 55/75
LLD Interview Notes: Day 33/50
Topic: Proxy Pattern
The Proxy Pattern is a structural design pattern that provides a substitute object to control access to the actual object.
Key Concepts:
Controls access to objects.
Supports lazy initialization.
Enables security checks and authorization.
Supports caching, logging, and remote access.
Real-World Example: Document Access
Client → Document Proxy → Real Document
The proxy verifies user permissions before allowing access to the actual document.
Types of Proxy:
Virtual Proxy: Lazy loading.
Protection Proxy: Access control.
Remote Proxy: Remote object access.
Caching Proxy: Reuses stored results.
Logging Proxy: Records operations.
Proxy vs Decorator:
Proxy controls access to an object.
Decorator adds behavior to an object.
FAANG Takeaway
The Proxy Pattern adds a control layer between the client and the real object without changing the object's implementation.
Remember:
The client talks to the Proxy. The Proxy controls access to the Real Subject.
Next: Day 34/50
Bridge Pattern in LLD
Blind 75: Day 54/75
Problem: Sliding Window Maximum
LeetCode 239: https://t.co/t9a54PUgUz
Given an array of integers nums and an integer k, there is a sliding window of size k that moves from the left to the right of the array.
Return the maximum value in each window.
You must solve it in O(n) time.
Example 1
Input: nums = [1,3,-1,-3,5,3,6,7], k = 3
Output: [3,3,5,5,6,7]
Explanation:
The maximum values in each window are:
[1,3,-1] → 3
[3,-1,-3] → 3
[-1,-3,5] → 5
[-3,5,3] → 5
[5,3,6] → 6
[3,6,7] → 7
Example 2
Input: nums = [1], k = 1
Output: [1]
Approach: Sliding Window + Monotonic Deque
Checking every element in every window would take O(n × k) time.
Instead, use a deque to maintain useful candidates for the maximum.
The deque stores indices in decreasing order of their corresponding values.
Step 1: Initialize
Create a deque to store indices.
Create a result array.
Iterate through the array using right.
Step 2: Remove Out-of-Window Elements
If the front index is outside the current window:
Remove it from the deque.
Condition:
deque.front() <= right - k
Step 3: Maintain Decreasing Order
While the deque is not empty and:
nums[deque.back()] <= nums[right]
Remove the back element.
Why?
The current element is larger, so the smaller element can never become the maximum while the current element remains in the window.
Step 4: Add the Current Index
Push right into the deque.
The front of the deque now represents the maximum element's index.
Step 5: Store the Maximum
Once the first complete window is formed (right >= k - 1):
Add nums[deque.front()] to the result.
Key Observation
The deque maintains indices of potential maximum elements in decreasing order of their values.
Smaller elements are removed when a larger element arrives because they can no longer become the maximum before leaving the window.
Complexity
Time: O(n)
Space: O(k)
Each index is inserted and removed at most once.
FAANG Takeaway
Sliding Window Maximum demonstrates how a Monotonic Deque can optimize a sliding window problem.
Instead of recalculating the maximum for every window, maintain only the elements that can still become the maximum.
Remember:
Keep the deque decreasing. Remove expired indices. The front always gives the maximum.
Next: Day 55/75
Ultimate DSA Premium Kit 👇
Get the Ultimate DSA Premium Kit: https://t.co/g4E6x1XJPQ
Your complete system for coding interview preparation.
Most DSA resources give you a list of problems to solve.
But knowing what to solve, which pattern to apply, and how to approach an unfamiliar problem is what actually matters in interviews.
That's why I put together the Ultimate DSA Premium Kit.
What's included?
📚 Learning & Roadmap
→ Complete DSA roadmap
→ 30+ topic-wise DSA notes
→ Pattern recognition guide
→ Algorithm master sheet
→ DSA cheat sheets for quick revision
💻 Problem Solving & Practice
→ 150 interview-focused problems
→ Step-by-step solution playbook
→ LeetCode strategy and interview mode
→ Company-wise DSA preparation
📅 Planning & Tracking
→ 30 / 60 / 90-day study plans
→ Progress tracker and mistake log
→ Weekly review and mock interview tracker
→ Revision and mastery system
🎯 Additional Resources
→ Guide for getting unstuck on difficult problems
→ Curated YouTube, GitHub, and LeetCode resources
The goal isn't to solve 500 random problems.
It's to build a structured process around:
→ What to study
→ What to practice
→ Which pattern to recognise
→ How to approach a problem
→ How to identify your mistakes
→ What to revise next
Everything is organised in one place, so you spend less time searching for resources and more time preparing.
If you're preparing for SDE interviews and want a structured DSA preparation system, check it out.
Blind 75: Day 53/75
Problem: Minimum Window Substring
LeetCode 76: https://t.co/tbGDm4reLf
Given two strings s and t, return the minimum window substring of s that contains every character from t, including duplicate characters.
If no such window exists, return an empty string.
You must solve it efficiently using Sliding Window.
Example 1
Input: s = "ADOBECODEBANC", t = "ABC"
Output: "BANC"
Explanation: The substring "BANC" is the smallest window containing A, B, and C.
Example 2
Input: s = "a", t = "a"
Output: "a"
Example 3
Input: s = "a", t = "aa"
Output: ""
Explanation: The string does not contain enough occurrences of 'a'.
Approach: Sliding Window + Frequency Counting
Instead of checking every possible substring, use two pointers to maintain a window and find the smallest valid substring.
Step 1: Initialize Variables
• Create a frequency map for characters in t.
• Maintain a window frequency map.
• Initialize left = 0.
• Track the number of characters whose required frequency has been satisfied.
• Store the minimum window length and starting index.
Step 2: Expand the Window
Move right through string s.
For every character:
→ Increase its frequency in the window.
→ If its frequency matches the required frequency in t, increment the formed count.
Step 3: Check Whether the Window Is Valid
The window is valid when:
formed == required
This means all required characters, including duplicates, are present.
Step 4: Shrink the Window
While the window remains valid:
→ Update the minimum window if the current one is smaller.
→ Remove the character at the left pointer.
→ If removing it makes its frequency fall below the required count, decrement formed.
→ Move left forward.
Step 5: Return the Answer
Return the smallest valid substring found.
If no valid window exists, return an empty string.
Key Observation
The goal is not just to find a substring containing all required characters.
It is to find the smallest such substring.
Expand the window until it becomes valid, then shrink it as much as possible without losing validity.
Complexity
Time: O(n + m)
Space: O(1) for a fixed character set, or O(n + m) with general-purpose hash maps.
Where n = length of s and m = length of t.
FAANG Takeaway
Minimum Window Substring is a classic example of the Sliding Window technique.
The key is to expand the window until all requirements are satisfied, then shrink it to find the smallest valid result.
Remember:
Expand to become valid. Shrink to become optimal.
Next: Day 54/75
Either this man is a once-in-a-generation investor or the luckiest human alive.
Airbnb, Uber, Spotify, Bitcoin, and now Anthropic.
At this point, I'm genuinely confused. 👀
AI Engineering projects worth building in 2026. 📌
AI AGENTS + MULTI-AGENT PROJECTS
Tiny Coding Agent: https://t.co/3YEvlVZ9wi
Browser Agent: https://t.co/QF9X4TeQVY
Streaming Agent Shell in Rust: https://t.co/AbpeFGl72U
Multi-Agent Code Review Panel: https://t.co/im07oRJbfo
Durable Agent Jobs: https://t.co/zP4HabeGSg
And many more.
RAG AND EVALUATION PROJECTS
Document QA with Citations: https://t.co/7PL2bhCet6
Retrieval Evaluation Lab: https://t.co/cHoNfqAP8I
Prompt Regression Tester: https://t.co/U6K72oMNxU
RAG Freshness Pipeline: https://t.co/ssFtdD5RfV
Local Model Evaluation Harness: https://t.co/3udxZ0pyjO
And many more.
LLM AND PRODUCTION TOOL-CALLING PROJECTS
LLM Gateway with Fallbacks: https://t.co/S0CSGFsyjM
Tool Call Firewall: https://t.co/nw43Wq5uqk
Sandbox Policy Planner: https://t.co/GunuBNAp5b
Persistent Memory Server: https://t.co/ukEAOYtg3j
MCP Tool Discovery Workbench: https://t.co/8RmRi8W4ex
Explore the repository:
https://t.co/rsDnuO3lkY
Official website:
https://t.co/lY0jfsbJip
A great collection to explore if you're serious about moving beyond basic LLM API calls and learning how production AI systems are actually built.
AI Engineering projects worth building in 2026. 📌
AI AGENTS + MULTI-AGENT PROJECTS
Tiny Coding Agent: https://t.co/3YEvlVZ9wi
Browser Agent: https://t.co/QF9X4TeQVY
Streaming Agent Shell in Rust: https://t.co/AbpeFGl72U
Multi-Agent Code Review Panel: https://t.co/im07oRJbfo
Durable Agent Jobs: https://t.co/zP4HabeGSg
And many more.
RAG AND EVALUATION PROJECTS
Document QA with Citations: https://t.co/7PL2bhCet6
Retrieval Evaluation Lab: https://t.co/cHoNfqAP8I
Prompt Regression Tester: https://t.co/U6K72oMNxU
RAG Freshness Pipeline: https://t.co/ssFtdD5RfV
Local Model Evaluation Harness: https://t.co/3udxZ0pyjO
And many more.
LLM AND PRODUCTION TOOL-CALLING PROJECTS
LLM Gateway with Fallbacks: https://t.co/S0CSGFsyjM
Tool Call Firewall: https://t.co/nw43Wq5uqk
Sandbox Policy Planner: https://t.co/GunuBNAp5b
Persistent Memory Server: https://t.co/ukEAOYtg3j
MCP Tool Discovery Workbench: https://t.co/8RmRi8W4ex
Explore the repository:
https://t.co/rsDnuO3lkY
Official website:
https://t.co/lY0jfsbJip
A great collection to explore if you're serious about moving beyond basic LLM API calls and learning how production AI systems are actually built.
What if your AI agent didn't need to search your entire knowledge base every time it needed an answer?
That's the interesting idea behind Google's Open Knowledge Format (OKF).
Inspired by Andrej Karpathy's LLM Wiki concept, OKF introduces a simple way to organize knowledge so AI agents can navigate it more efficiently.
Here's how it works:
1. Store knowledge as Markdown files
→ One file per topic.
→ A small YAML frontmatter block identifies the content type.
→ An index.md file explains what's available in each folder.
2. Connect knowledge like a wiki
→ Use regular Markdown links between related topics.
→ Let agents follow those links to discover relevant information.
→ Keep the knowledge base readable by both humans and AI.
3. Keep it portable
→ Share it through Git, ZIP files, or tarballs.
→ No special SDK required.
→ Different AI pipelines can read and write the same knowledge structure.
But here's the important distinction:
OKF and RAG solve different problems.
OKF helps organize and maintain knowledge.
RAG retrieves relevant information from a knowledge source to answer a query.
They can work together.
Instead of treating every query as a fresh search across an unstructured collection of documents, an agent can navigate an organized knowledge base and retrieve the context it needs.
Why this matters:
Better context organization can mean less redundant searching, more focused retrieval, and potentially lower inference costs.
The bigger takeaway?
As AI agents become more capable, how we structure and maintain their knowledge may matter just as much as which model we use.
RAG isn't dead. Knowledge management is evolving.
What if your AI agent didn't need to search your entire knowledge base every time it needed an answer?
That's the interesting idea behind Google's Open Knowledge Format (OKF).
Inspired by Andrej Karpathy's LLM Wiki concept, OKF introduces a simple way to organize knowledge so AI agents can navigate it more efficiently.
Here's how it works:
1. Store knowledge as Markdown files
→ One file per topic.
→ A small YAML frontmatter block identifies the content type.
→ An index.md file explains what's available in each folder.
2. Connect knowledge like a wiki
→ Use regular Markdown links between related topics.
→ Let agents follow those links to discover relevant information.
→ Keep the knowledge base readable by both humans and AI.
3. Keep it portable
→ Share it through Git, ZIP files, or tarballs.
→ No special SDK required.
→ Different AI pipelines can read and write the same knowledge structure.
But here's the important distinction:
OKF and RAG solve different problems.
OKF helps organize and maintain knowledge.
RAG retrieves relevant information from a knowledge source to answer a query.
They can work together.
Instead of treating every query as a fresh search across an unstructured collection of documents, an agent can navigate an organized knowledge base and retrieve the context it needs.
Why this matters:
Better context organization can mean less redundant searching, more focused retrieval, and potentially lower inference costs.
The bigger takeaway?
As AI agents become more capable, how we structure and maintain their knowledge may matter just as much as which model we use.
RAG isn't dead. Knowledge management is evolving.
HLD Interview Notes: Day 29/30
Topic: Service Level Indicators (SLIs), Service Level Objectives (SLOs) and Service Level Agreements (SLAs)
Imagine you're running a payment application.
Customers expect payments to complete quickly and successfully.
But how do you measure whether your system is reliable?
How much downtime is acceptable?
What response time should your API maintain?
And what happens if your application fails to meet its promised availability?
This is where SLIs, SLOs, and SLAs become important.
What Are SLIs, SLOs and SLAs?
These three concepts help define, measure, and manage service reliability.
They are closely related but serve different purposes.
A. Service Level Indicator (SLI)
An SLI is a measurable metric that tells us how well a service is performing.
Examples:
• Request success rate.
• API response latency.
• Availability percentage.
• Error rate.
• Throughput.
Example:
If 99,500 out of 100,000 requests succeed:
SLI = 99.5% success rate.
B. Service Level Objective (SLO)
An SLO is a target value for an SLI over a specific period.
It defines the reliability level a service aims to maintain.
Example:
API Availability SLO = 99.9% over 30 days.
This means the service aims to remain available for 99.9% of the measurement period.
C. Service Level Agreement (SLA)
An SLA is a formal agreement between a service provider and its customer.
It defines the expected service level and what happens if the provider fails to meet the agreed commitment.
Examples:
• Guaranteed availability.
• Support response times.
• Service credits for qualifying downtime.
• Contractual responsibilities.
Real-World Example: Payment Application
Imagine you're operating an online payment platform.
Your reliability requirements are:
SLI:
Measure the percentage of successful payment requests.
SLO:
Maintain 99.9% successful payment requests over 30 days.
SLA:
Promise customers 99.5% monthly availability, with service credits if the contractual conditions are met.
The distinction:
SLI = What you measure.
SLO = What you target.
SLA = What you formally promise.
Understanding Availability Percentages
Availability is commonly expressed using the number of nines.
Here is how availability targets translate into approximate downtime:
99% Availability:
Approximately 7.2 hours of downtime per month.
99.9% Availability:
Approximately 43.8 minutes per month.
99.99% Availability:
Approximately 4.38 minutes per month.
99.999% Availability:
Approximately 26 seconds per month.
Higher availability targets generally require more investment in infrastructure, redundancy, monitoring, and recovery mechanisms.
What Is an Error Budget?
An Error Budget is the amount of unreliability a service can tolerate while still meeting its SLO.
Formula:
Error Budget = 100% - SLO
Example:
If your availability SLO is 99.9%:
Error Budget = 0.1%
This means the service can experience approximately 0.1% unavailability within the measurement window before violating its SLO.
Why does it matter?
• Helps balance reliability and development speed.
• Allows teams to manage acceptable risk.
• Helps decide when to prioritize reliability improvements.
• Prevents teams from continuously shipping changes at the expense of stability.
What Happens When the Error Budget Is Exhausted?
Imagine your service has consumed its entire error budget.
The engineering team may:
• Pause risky deployments.
• Prioritize bug fixes and reliability improvements.
• Investigate recurring incidents.
• Improve monitoring and alerting.
• Strengthen infrastructure resilience.
The goal is to restore reliability before introducing more risk.
How SLIs, SLOs and SLAs Work Together
Think of them as three layers:
SLI → Measures actual service performance.
SLO → Defines the target performance.
SLA → Establishes the contractual commitment.
Example:
SLI: Current API availability is 99.95%.
SLO: Target API availability is 99.9%.
SLA: Contractual availability commitment is 99.5%.
The service currently meets both its SLO and SLA.
Where Are They Used?
• Cloud Computing Platforms.
• Payment Gateways.
• Banking Applications.
• SaaS Products.
• Microservices Architectures.
• API Platforms.
• E-commerce Applications.
• Distributed Systems.
Cloud providers also publish SLAs defining availability commitments for their services.
Best Practices
• Choose SLIs that reflect actual user experience.
• Set realistic and measurable SLOs.
• Keep SLOs separate from contractual SLAs.
• Monitor error budgets continuously.
• Define clear measurement windows.
• Alert on error budget consumption.
• Review reliability targets regularly.
• Avoid setting unrealistic 100% availability targets.
Common Interview Mistakes
• Confusing SLIs, SLOs, and SLAs.
• Assuming 100% availability is always achievable.
• Ignoring the measurement window.
• Treating infrastructure metrics as the only indicators of reliability.
• Forgetting the purpose of error budgets.
• Setting SLOs without considering user experience.
Interview Questions
What is an SLI?
What is an SLO?
What is an SLA?
What is the difference between SLI, SLO, and SLA?
What is an Error Budget?
How do you calculate an Error Budget?
What happens when an Error Budget is exhausted?
How would you define an SLO for a payment service?
How do availability percentages translate into downtime?
How do you choose meaningful SLIs for a distributed system?
How would you balance feature development with reliability?
FAANG Takeaway
Building a reliable system isn't just about preventing failures.
It's about defining measurable reliability targets, understanding acceptable failure limits, and continuously improving the user experience.
SLIs tell you how your system performs.
SLOs tell you how well it should perform.
SLAs define what you have committed to your customers.
Remember:
Measure performance. Set reliability targets. Manage the error budget.
Next: Day 30/30
System Design Interview: Putting Everything Together
Blind 75: Day 53/75
Problem: Minimum Window Substring
LeetCode 76: https://t.co/tbGDm4reLf
Given two strings s and t, return the minimum window substring of s that contains every character from t, including duplicate characters.
If no such window exists, return an empty string.
You must solve it efficiently using Sliding Window.
Example 1
Input: s = "ADOBECODEBANC", t = "ABC"
Output: "BANC"
Explanation: The substring "BANC" is the smallest window containing A, B, and C.
Example 2
Input: s = "a", t = "a"
Output: "a"
Example 3
Input: s = "a", t = "aa"
Output: ""
Explanation: The string does not contain enough occurrences of 'a'.
Approach: Sliding Window + Frequency Counting
Instead of checking every possible substring, use two pointers to maintain a window and find the smallest valid substring.
Step 1: Initialize Variables
• Create a frequency map for characters in t.
• Maintain a window frequency map.
• Initialize left = 0.
• Track the number of characters whose required frequency has been satisfied.
• Store the minimum window length and starting index.
Step 2: Expand the Window
Move right through string s.
For every character:
→ Increase its frequency in the window.
→ If its frequency matches the required frequency in t, increment the formed count.
Step 3: Check Whether the Window Is Valid
The window is valid when:
formed == required
This means all required characters, including duplicates, are present.
Step 4: Shrink the Window
While the window remains valid:
→ Update the minimum window if the current one is smaller.
→ Remove the character at the left pointer.
→ If removing it makes its frequency fall below the required count, decrement formed.
→ Move left forward.
Step 5: Return the Answer
Return the smallest valid substring found.
If no valid window exists, return an empty string.
Key Observation
The goal is not just to find a substring containing all required characters.
It is to find the smallest such substring.
Expand the window until it becomes valid, then shrink it as much as possible without losing validity.
Complexity
Time: O(n + m)
Space: O(1) for a fixed character set, or O(n + m) with general-purpose hash maps.
Where n = length of s and m = length of t.
FAANG Takeaway
Minimum Window Substring is a classic example of the Sliding Window technique.
The key is to expand the window until all requirements are satisfied, then shrink it to find the smallest valid result.
Remember:
Expand to become valid. Shrink to become optimal.
Next: Day 54/75