MindForge
MindForge
DashboardHelp & Support
Dashboard
MindForge

Interview Preparation Bootcamp

Course progress

0%
0 of 177 modules complete
Start Here0/1
  • How to Use This Course
Data Structures & Algorithms0/27
  • Arrays and Hashing
  • Two Pointers
  • Sliding Window
  • Sliding Window: Harder Problems
  • Binary Search
  • Stacks
  • Practice Test: Arrays, Pointers, Windows, Search and Stacks
  • Trees: Traversals and Core Patterns
  • Binary Search Trees and Rebuilding a Tree
  • Tries (Prefix Trees)
  • Heaps and Priority Queues
  • Graphs: BFS and DFS
  • Topological Sort and Cycle Detection
  • Union-Find (Disjoint Set Union)
  • Practice Test: Trees, Heaps and Graphs
  • Dynamic Programming Basics
  • Dynamic Programming: Two Dimensions
  • Dynamic Programming: Hard String Matching
  • Backtracking
  • Backtracking: Constraint Satisfaction
  • Greedy Algorithms
  • Interval Problems
  • Bit Manipulation
  • Math and Geometry
  • String Manipulation
  • Pattern Recall and Mock Coding Rounds
  • Practice Test: DP, Backtracking, Greedy and More

System Design

Foundations0/16
  • The System Design Interview Framework
  • Back-of-the-Envelope Estimation
  • Networking and Protocols for Design
  • API Design and Idempotency
  • Load Balancing, Proxies, and Scaling Out
  • Caching and CDNs
  • Choosing a Database: Storage, Indexes and Transactions
  • Replication, Partitioning, and Sharding
  • CAP, PACELC, and Levels of Consistency
  • Messaging, Queues, and Event-Driven Architecture
  • Distributed Transactions and Data Integrity
  • Coordination, Consensus, and Distributed Locks
  • Reliability, Resilience, and Rate Limiting
  • Observability, Security, and Cost
  • System Design Cheat Sheet
  • Practice Test: System Design Foundations
Case Studies0/23
  • Design a URL Shortener
  • Design a Rate Limiter
  • Design a Notification Service
  • Design a Job Queue System
  • Design a Chat App (WhatsApp)
  • Design an Analytics Pipeline
  • Design a Multi-tenant SaaS Architecture
  • Design a Social Media Feed (Twitter/X)
  • Design a Search Autocomplete System
  • Design a File Storage Service (Dropbox)
  • Design Google Docs
  • Design a Code Review System
  • Design Netflix
  • Design YouTube
  • Design Spotify
  • Design Uber/Lyft
  • Design Airbnb
  • Design Ticketmaster (Eventbrite)
  • Design an E-commerce Cart, Checkout, and Catalog
  • Design a Payment System
  • Design a Logging and Monitoring System
  • Mock Design Rounds
  • Practice Test: System Design Case Studies
Low-Level Design0/19
  • The LLD Interview Framework and UML
  • OOP Foundations for Design
  • SOLID Principles
  • Creational Patterns
  • Structural Patterns
  • Behavioral Patterns I — Strategy, Observer, Command, State, Template Method
  • Behavioral Patterns II and Anti-Patterns
  • Concurrency in Low-Level Design
  • Design a Parking Lot
  • Design an Elevator System
  • Design a Movie Ticket Booking System
  • Design an Expense-Sharing App (Splitwise)
  • Design a Vending Machine and an ATM
  • Design a Rate Limiter and a Logging Framework
  • Design a Notification Service and an In-Memory Cache
  • Design Games — Tic-Tac-Toe, Snake and Ladder, Chess
  • Database Design for LLD
  • LLD Cheat Sheet and Recall Drill
  • Practice Test: Low-Level Design

Backend

Python0/5
  • How Python Runs Your Code
  • Functions Deep Dive: Closures, Generators, Context Managers, Scope
  • Classes Deep Dive: Method Types, MRO, Metaclasses
  • Standard Library and Serialization
  • Practice Test: Python
Django0/6
  • Django Request Lifecycle
  • Lab: Django Middleware — Request ID & Response Time
  • Django ORM and Querysets
  • Django's Cache Framework
  • Practice Test: Django
  • Django in Production: Debugging Labs
FastAPI0/5
  • FastAPI, ASGI, and Async
  • FastAPI Dependency Injection
  • FastAPI Background Tasks
  • Lab: FastAPI Async — Concurrent Aggregation
  • Practice Test: FastAPI
Databases (PostgreSQL)0/6
  • Indexing
  • Query Optimization
  • Transactions and Isolation
  • Migrations and Schema Changes
  • Hierarchical Data and Safe Concurrent Updates
  • Practice Test: Databases
Caching, Queues & Distributed Systems0/8
  • Redis Caching
  • Redis Advanced Patterns
  • Celery and Background Workers
  • Kafka and Message Queues
  • Async Pipelines
  • Distributed Systems Basics
  • Distributed Locks
  • Practice Test: Caching, Queues and Distributed Systems
APIs, Security & Deployment0/9
  • REST API Design
  • API Versioning and Error Handling
  • API Security and Authentication
  • WebSockets and Real-Time Systems
  • Docker and Containers
  • File Storage with S3
  • Testing Strategies
  • Mock Backend Round
  • Practice Test: APIs, Security and Deployment
Frontend0/38
  • HTML Document Structure and Semantics
  • CSS Box Model, Flexbox and Grid
  • CSS Architecture and Theming
  • CSS and Rendering Performance
  • Variables, Scope, Hoisting, and Truthiness
  • Functions, this, and Binding
  • Objects and Prototypal Inheritance
  • JavaScript Utility Patterns: Cloning, Caching, and Memory
  • Promises From Scratch
  • The Event Loop and Browser Rendering Pipeline
  • The DOM: Nodes, Events, and Traversal
  • Practice Test: HTML, CSS and JavaScript
  • React Rendering Fundamentals
  • React Hooks Internals
  • React Performance
  • Lab: React — Stateful Counter Component
  • State Management
  • State Machines in React
  • React Custom Hooks and Composition Patterns
  • TypeScript for React
  • React Testing
  • Practice Test: React
  • HTTP and Caching
  • Network Performance and Web Vitals
  • Code Splitting and Bundles
  • Virtualization
  • GraphQL and Data Fetching
  • Web Security
  • WebSockets and Real-time
  • SSR and Next.js
  • Micro-frontends
  • Build Tools and Bundling
  • Accessibility
  • Error Handling
  • Internationalization
  • Animation
  • Rapid Recall and Mock Frontend Rounds
  • Practice Test: Performance, Architecture and Production
Behavioral & Interview Day0/14
  • Resume and Project Walkthroughs
  • The STAR Method and Refining Your Stories
  • Conflict and Difficult Coworkers
  • Failures, Incidents, and Obstacles
  • Leadership, Mentorship, and Ownership
  • Teamwork, Communication, and Feedback
  • Growth and Handling Ambiguity
  • Career Goals, Why This Company, and Negotiation
  • Situational Questions
  • Company Research
  • Mock Behavioral Rounds
  • Interview Day
  • After the Interview
  • Practice Test: Behavioral and Interview Day
Sliding Window: Harder Problems
Course contents

Interview Preparation Bootcamp

Course progress

0%
0 of 177 modules complete
Start Here0/1
  • How to Use This Course
Data Structures & Algorithms0/27
  • Arrays and Hashing
  • Two Pointers
  • Sliding Window
  • Sliding Window: Harder Problems
  • Binary Search
  • Stacks
  • Practice Test: Arrays, Pointers, Windows, Search and Stacks
  • Trees: Traversals and Core Patterns
  • Binary Search Trees and Rebuilding a Tree
  • Tries (Prefix Trees)
  • Heaps and Priority Queues
  • Graphs: BFS and DFS
  • Topological Sort and Cycle Detection
  • Union-Find (Disjoint Set Union)
  • Practice Test: Trees, Heaps and Graphs
  • Dynamic Programming Basics
  • Dynamic Programming: Two Dimensions
  • Dynamic Programming: Hard String Matching
  • Backtracking
  • Backtracking: Constraint Satisfaction
  • Greedy Algorithms
  • Interval Problems
  • Bit Manipulation
  • Math and Geometry
  • String Manipulation
  • Pattern Recall and Mock Coding Rounds
  • Practice Test: DP, Backtracking, Greedy and More

System Design

Foundations0/16
  • The System Design Interview Framework
  • Back-of-the-Envelope Estimation
  • Networking and Protocols for Design
  • API Design and Idempotency
  • Load Balancing, Proxies, and Scaling Out
  • Caching and CDNs
  • Choosing a Database: Storage, Indexes and Transactions
  • Replication, Partitioning, and Sharding
  • CAP, PACELC, and Levels of Consistency
  • Messaging, Queues, and Event-Driven Architecture
  • Distributed Transactions and Data Integrity
  • Coordination, Consensus, and Distributed Locks
  • Reliability, Resilience, and Rate Limiting
  • Observability, Security, and Cost
  • System Design Cheat Sheet
  • Practice Test: System Design Foundations
Case Studies0/23
  • Design a URL Shortener
  • Design a Rate Limiter
  • Design a Notification Service
  • Design a Job Queue System
  • Design a Chat App (WhatsApp)
  • Design an Analytics Pipeline
  • Design a Multi-tenant SaaS Architecture
  • Design a Social Media Feed (Twitter/X)
  • Design a Search Autocomplete System
  • Design a File Storage Service (Dropbox)
  • Design Google Docs
  • Design a Code Review System
  • Design Netflix
  • Design YouTube
  • Design Spotify
  • Design Uber/Lyft
  • Design Airbnb
  • Design Ticketmaster (Eventbrite)
  • Design an E-commerce Cart, Checkout, and Catalog
  • Design a Payment System
  • Design a Logging and Monitoring System
  • Mock Design Rounds
  • Practice Test: System Design Case Studies
Low-Level Design0/19
  • The LLD Interview Framework and UML
  • OOP Foundations for Design
  • SOLID Principles
  • Creational Patterns
  • Structural Patterns
  • Behavioral Patterns I — Strategy, Observer, Command, State, Template Method
  • Behavioral Patterns II and Anti-Patterns
  • Concurrency in Low-Level Design
  • Design a Parking Lot
  • Design an Elevator System
  • Design a Movie Ticket Booking System
  • Design an Expense-Sharing App (Splitwise)
  • Design a Vending Machine and an ATM
  • Design a Rate Limiter and a Logging Framework
  • Design a Notification Service and an In-Memory Cache
  • Design Games — Tic-Tac-Toe, Snake and Ladder, Chess
  • Database Design for LLD
  • LLD Cheat Sheet and Recall Drill
  • Practice Test: Low-Level Design

Backend

Python0/5
  • How Python Runs Your Code
  • Functions Deep Dive: Closures, Generators, Context Managers, Scope
  • Classes Deep Dive: Method Types, MRO, Metaclasses
  • Standard Library and Serialization
  • Practice Test: Python
Django0/6
  • Django Request Lifecycle
  • Lab: Django Middleware — Request ID & Response Time
  • Django ORM and Querysets
  • Django's Cache Framework
  • Practice Test: Django
  • Django in Production: Debugging Labs
FastAPI0/5
  • FastAPI, ASGI, and Async
  • FastAPI Dependency Injection
  • FastAPI Background Tasks
  • Lab: FastAPI Async — Concurrent Aggregation
  • Practice Test: FastAPI
Databases (PostgreSQL)0/6
  • Indexing
  • Query Optimization
  • Transactions and Isolation
  • Migrations and Schema Changes
  • Hierarchical Data and Safe Concurrent Updates
  • Practice Test: Databases
Caching, Queues & Distributed Systems0/8
  • Redis Caching
  • Redis Advanced Patterns
  • Celery and Background Workers
  • Kafka and Message Queues
  • Async Pipelines
  • Distributed Systems Basics
  • Distributed Locks
  • Practice Test: Caching, Queues and Distributed Systems
APIs, Security & Deployment0/9
  • REST API Design
  • API Versioning and Error Handling
  • API Security and Authentication
  • WebSockets and Real-Time Systems
  • Docker and Containers
  • File Storage with S3
  • Testing Strategies
  • Mock Backend Round
  • Practice Test: APIs, Security and Deployment
Frontend0/38
  • HTML Document Structure and Semantics
  • CSS Box Model, Flexbox and Grid
  • CSS Architecture and Theming
  • CSS and Rendering Performance
  • Variables, Scope, Hoisting, and Truthiness
  • Functions, this, and Binding
  • Objects and Prototypal Inheritance
  • JavaScript Utility Patterns: Cloning, Caching, and Memory
  • Promises From Scratch
  • The Event Loop and Browser Rendering Pipeline
  • The DOM: Nodes, Events, and Traversal
  • Practice Test: HTML, CSS and JavaScript
  • React Rendering Fundamentals
  • React Hooks Internals
  • React Performance
  • Lab: React — Stateful Counter Component
  • State Management
  • State Machines in React
  • React Custom Hooks and Composition Patterns
  • TypeScript for React
  • React Testing
  • Practice Test: React
  • HTTP and Caching
  • Network Performance and Web Vitals
  • Code Splitting and Bundles
  • Virtualization
  • GraphQL and Data Fetching
  • Web Security
  • WebSockets and Real-time
  • SSR and Next.js
  • Micro-frontends
  • Build Tools and Bundling
  • Accessibility
  • Error Handling
  • Internationalization
  • Animation
  • Rapid Recall and Mock Frontend Rounds
  • Practice Test: Performance, Architecture and Production
Behavioral & Interview Day0/14
  • Resume and Project Walkthroughs
  • The STAR Method and Refining Your Stories
  • Conflict and Difficult Coworkers
  • Failures, Incidents, and Obstacles
  • Leadership, Mentorship, and Ownership
  • Teamwork, Communication, and Feedback
  • Growth and Handling Ambiguity
  • Career Goals, Why This Company, and Negotiation
  • Situational Questions
  • Company Research
  • Mock Behavioral Rounds
  • Interview Day
  • After the Interview
  • Practice Test: Behavioral and Interview Day
Browsing without an account — progress is saved in this browser only.Sign in to save it

Sliding Window: Harder Problems

Reading120 min

The Sliding Window lesson covered a window tracked by one running number, a sum, a minimum, a single count. Picture that same train of connected cars, but now the conductor also has to track something more detailed about the 3 cars in view: how many different colors are among them, or whether at most 2 of them are red. This lesson covers exactly that: windows that need a whole frequency count instead of one number, and windows that must satisfy more than one rule at once. This is the pattern behind most "longest/shortest substring or subarray with property X" interview questions once they get past the beginner stage.

Fixed window with data structures

Picture a security guard watching the last 4 people to badge through a door, keeping a running tally of how many different departments are among those 4. When a 5th person badges in, the guard does not recount all 4 people from scratch: they add the new person's department to the tally and remove the department of whoever just aged out the back of the window. A fixed-size window slides the same way, one element at a time. Instead of just a running sum, you often keep a frequency map or count that updates incrementally as elements enter and leave.

from collections import Counter

def max_distinct_in_window(nums: list[int], k: int) -> int:
    counts = Counter(nums[:k])
    best = len(counts)
    for i in range(k, len(nums)):
        counts[nums[i]] += 1                 # element entering
        left = nums[i - k]
        counts[left] -= 1                    # element leaving
        if counts[left] == 0:
            del counts[left]                 # keep the map accurate for len() checks
        best = max(best, len(counts))
    return best

Every fixed-window problem does exactly two things per step: add the incoming element's effect, remove the outgoing element's effect. That "effect" can be a sum, a frequency count, a max-tracking deque, or anything else you can maintain incrementally. Never recompute the whole window from scratch each step, since that turns an O(n) sliding window into O(n·k).

Remember: a fixed window does two things per step, add the new element's effect, remove the old element's effect. Never rescan the whole window.

Sign in to try this knowledge check.

Variable window tracking multiple conditions

Picture that same guard, but now with two rules at once: "let at most 2 departments through together, and never let the group at the door grow past 15 people." The guard still does the same two things as before, let people in from the front, remove people from the back only when a rule breaks, just checking two rules instead of one. A variable-size window grows by advancing right and shrinks by advancing left, expanding while a condition holds and contracting when it is violated. The harder version tracks several conditions at once, for example "at most 2 distinct characters and window length under some bound."

def variable_window_skeleton(s: str, is_valid) -> int:
    left = 0
    best = 0
    window_state = {}  # whatever data the condition needs: counts, max-freq, etc.

    for right in range(len(s)):
        # 1. expand: absorb s[right] into window_state
        window_state[s[right]] = window_state.get(s[right], 0) + 1

        # 2. contract while the window violates the condition
        while not is_valid(window_state, right - left + 1):
            window_state[s[left]] -= 1
            if window_state[s[left]] == 0:
                del window_state[s[left]]
            left += 1

        # 3. record the best valid window at this right boundary
        best = max(best, right - left + 1)

    return best

The invariant to hold onto: left only ever moves forward. It never resets to 0 and rescans. That is what makes the whole algorithm O(n) instead of O(n²): each index enters and leaves the window at most once across the entire run.

Remember: is_valid can check any number of conditions at once, the expand/contract skeleton around it never changes.

Sign in to try this knowledge check.

Longest Repeating Character Replacement

LeetCode 424

Intuition: You can change up to k characters in a window to make every character the same. A window is valid if window_length - count_of_most_frequent_char <= k, which is exactly the number of characters you would need to replace.

Approach: Expand right, tracking a frequency count and the running max frequency seen. max_freq never needs to decrease even as the window shrinks. It only ever underestimates slightly, but that is safe, since the answer only grows when a new max_freq is achieved, so a stale max_freq cannot produce a wrong, too-large answer. Shrink left only when the window becomes invalid.

def characterReplacement(s: str, k: int) -> int:
    counts = {}
    left = 0
    max_freq = 0
    best = 0

    for right in range(len(s)):
        counts[s[right]] = counts.get(s[right], 0) + 1
        max_freq = max(max_freq, counts[s[right]])

        window_len = right - left + 1
        if window_len - max_freq > k:
            counts[s[left]] -= 1
            left += 1

        best = max(best, right - left + 1)

    return best

Complexity: Time O(n), space O(1) (at most 26 letters in counts).

Common mistakes: Trying to decrement max_freq when the window shrinks is unnecessary, and actually breaks the O(n) guarantee if done with a full rescan. Also, forgetting that best can be computed from the window length even mid-shrink, since the window never needs to shrink below the best length found so far; it can only stay the same or grow.

Remember: max_freq never needs to shrink, even when the window does. The answer can only grow.

Sign in to try this knowledge check.

Fruit Into Baskets

LeetCode 904

Intuition: This is "longest subarray with at most 2 distinct values" wearing a word problem's clothes. Two baskets means at most 2 distinct fruit types in the window.

Approach: Expand right, tracking fruit-type counts in a map. While the map has more than 2 keys, shrink left.

def totalFruit(fruits: list[int]) -> int:
    counts = {}
    left = 0
    best = 0

    for right, fruit in enumerate(fruits):
        counts[fruit] = counts.get(fruit, 0) + 1

        while len(counts) > 2:
            left_fruit = fruits[left]
            counts[left_fruit] -= 1
            if counts[left_fruit] == 0:
                del counts[left_fruit]
            left += 1

        best = max(best, right - left + 1)

    return best

Complexity: Time O(n), space O(1) (at most 3 keys in counts at any moment, since you shrink the instant it hits 3).

Common mistakes: Not recognizing the "2 baskets" framing as "at most 2 distinct values." Translating a word problem into the underlying pattern is the real skill being tested. Also, forgetting to delete zero-count entries from the map, which corrupts the len(counts) > 2 check.

Remember: "2 baskets" is just "at most 2 distinct values" in a costume. Learn to spot the pattern under the wording.

Sign in to try this knowledge check.

Minimum Size Subarray Sum

LeetCode 209

Intuition: Find the shortest contiguous subarray with sum at least target. This flips the usual "maximize the window" pattern into "minimize the window while a condition holds," but the two-pointer mechanics are identical.

Approach: Expand right, adding to a running sum. While the sum meets or exceeds target, record the window length and shrink left, continuing to shrink while it is still valid, since a smaller valid window is always better here.

def minSubArrayLen(target: int, nums: list[int]) -> int:
    left = 0
    total = 0
    best = float('inf')

    for right, num in enumerate(nums):
        total += num

        while total >= target:
            best = min(best, right - left + 1)
            total -= nums[left]
            left += 1

    return best if best != float('inf') else 0

Complexity: Time O(n), space O(1).

Common mistakes: Using if instead of while when shrinking. A single conditional shrink misses shorter valid windows that stay valid after one shrink step. Also, forgetting the "no valid subarray exists" case, which needs to return 0, not inf or -1.

Remember: when minimizing, shrink with a while, not an if, and record the answer on every shrink, not just once.

Sign in to try this knowledge check.

Longest Subarray with Ones after Replacement

Also known as Max Consecutive Ones III (LeetCode 1004), the array version of Longest Repeating Character Replacement.

Intuition: You can flip up to k zeros to ones. Find the longest subarray you can make this way. This is structurally identical to Longest Repeating Character Replacement: a window is valid if zero_count_in_window <= k.

Approach: Expand right, tracking the count of zeros in the window. Shrink left while the zero count exceeds k.

def longestOnes(nums: list[int], k: int) -> int:
    left = 0
    zero_count = 0
    best = 0

    for right, num in enumerate(nums):
        if num == 0:
            zero_count += 1

        while zero_count > k:
            if nums[left] == 0:
                zero_count -= 1
            left += 1

        best = max(best, right - left + 1)

    return best

Complexity: Time O(n), space O(1).

Common mistakes: Building a full frequency map when a simple zero counter is enough. Only two values exist here, 0 and 1, so there is no need for a map, unlike the character-replacement version with 26 possible letters. Also, off-by-one when computing window length after the shrink loop exits.

Step back, and the four problems above split into just two templates: "at most K distinct" (Fruit Into Baskets) and "longest valid window after up to K changes" (Character Replacement, Max Consecutive Ones III). Minimum Size Subarray Sum is the mirror image of both, shrinking instead of growing. Once you can name which template a new problem matches, the two-pointer skeleton writes itself.

Remember: four problems, two templates. Name the template first, then the code is mechanical.

Sign in to try this knowledge check.
PreviousSliding WindowNextBinary Search

Course progress

0%
0 of 177 modules complete

On this page

  • Fixed window with data structures
  • Variable window tracking multiple conditions
  • Longest Repeating Character Replacement
  • Fruit Into Baskets
  • Minimum Size Subarray Sum
  • Longest Subarray with Ones after Replacement