CORRECT CODE INVESTIGATION / CASE FILE #006

Solve Minimum Window Substring

Prove how count-sensitive coverage permits a window to contract lawfully.

REASON BEFORE CODE.
01

THE ASSIGNMENT

Find the Shortest Substring That Covers Every Required Character

The Objective

Given two strings named "s"" and "t", identify the shortest substring of "s" that contains every character required by "t".

The required substring must satisfy the character requirements of "t", including the number of times each character occurs.

The result is the substring itself, not its length or its index positions. If no substring satisfies the requirements, the solution must return an empty string.

The investigation must establish how a valid covering sequence is identified and how its boundaries can be reduced without losing required character coverage.

REQUIRED OUTCOME Return the shortest substring of "s" that contains every character required by "t", including duplicate requirements, or return an empty string when no valid substring exists.
02

THE EVIDENCE

What Information Is Available?

The Inputs

The problem statement establishes two strings that serve different purposes in the investigation:

  • Source string: The string "s" contains the characters from which a candidate substring must be formed.
  • Requirement string: The string "t" establishes which characters must be covered.
  • Character positions: Each character occupies a position in its respective string.
  • Character counts: The number of occurrences of each required character matters.
  • Contiguity: A candidate substring must consist of consecutive positions in the source string.
  • Output: The shortest valid substring must be returned. If no valid candidate exists, the result is an empty string.
IMPORTANT EVIDENCE Character coverage is count-sensitive. A candidate must contain enough occurrences of each required character—not merely contain each required character at least once.

The investigation must distinguish between the characters present in a candidate substring and the exact quantities required by the second string.

03

THE CENTRAL DIFFICULTY

Finding Coverage Is Only Half the Problem

The Challenge

The solution must identify a contiguous sequence in "s" that satisfies every character requirement established by "t".

However, finding a valid covering sequence does not establish that the sequence is the shortest one.

Once all requirements are satisfied, the solution must determine whether the beginning of the active sequence can move forward without removing necessary evidence.

Each lawful contraction creates an opportunity to discover a shorter valid result. But removing a required occurrence can make the candidate invalid again.

01

What Must Be Covered?

Establish the character requirements from "t", including how many occurrences of each character are necessary.

02

Has Complete Coverage Been Established?

Determine whether the active substring contains enough occurrences of every required character.

03

Can the Window Contract?

Determine whether removing the character at the beginning boundary preserves every required character count.

04

Has a Shorter Valid Result Been Found?

Evaluate each valid candidate and preserve the shortest one discovered during the investigation.

05

When Does Coverage Become Invalid?

Establish which requirement is no longer satisfied when a necessary occurrence leaves the active sequence.

THE CENTRAL DIFFICULTY The challenge is not simply finding a window that contains the required characters. It is proving when that window can contract while preserving complete, count-sensitive coverage.
04

THE CCF INVESTIGATION

Reason Through the Solution Before Choosing Its Implementation

REASON BEFORE CODE.

The Correct Code Framework organizes the investigation into distinct reasoning spaces and decision responsibilities.

Base Component

The Base Component establishes the identity of the solution: MinimumWindowSubstring.

Problem Space

Establish the source string, requirement string, character positions, and the exact number of occurrences needed for complete coverage.

Answer Space

Define the required output: the shortest contiguous substring that satisfies every character requirement, or an empty string when no valid substring exists.

Decision Space

Determine whether the active substring provides complete coverage, whether its boundaries can move, and whether a shorter valid result has been found.

Scanner

Establish how characters from the source string are examined and how the active sequence expands as additional evidence is encountered.

Persistence and Recorder

Determine what information must remain available to compare the active substring against the requirements established by "t".

The Recorder must support count-sensitive evaluation. Knowing that a character is present is insufficient when the requirement calls for multiple occurrences.

The investigation must also establish how character counts and coverage remain accurate as the active boundaries change.

Completion

Establish when the source string has been fully examined, how the shortest valid candidate is preserved, and when an empty result must be returned.

THE INVESTIGATION PRINCIPLE Derive each responsibility from the problem's requirements. Do not select an implementation because it is familiar or convenient.
05

THE INVESTIGATION STANDARD

Establish Coverage Before Contracting

Scanner and Recorder

Minimum Window introduces a distinction between finding complete coverage and minimizing the boundaries of a sequence that already provides that coverage.

01

The Scanner

The Scanner determines which source character is being examined and advances the active sequence through the original string.

02

The Active Frame

The active boundaries establish the current contiguous candidate and determine which characters contribute to its coverage.

03

The Recorder

The Recorder preserves the character-count evidence needed to determine whether all requirements remain satisfied.

04

The Coverage Decision

The Decision Space establishes whether the active candidate contains enough occurrences of every required character to qualify as a valid covering substring.

The investigation must prove what complete coverage means, how character counts affect validity, and why a boundary can move only when the remaining sequence still satisfies every requirement.

It must also establish when a valid candidate should be recorded as the current shortest result and what happens when contraction removes a necessary occurrence.

Only after these responsibilities are established should the appropriate data structure, technique, algorithm, and implementation be selected.

THE OBJECTIVE The objective is not to memorize Minimum Window Substring. It is to prove how complete character coverage permits lawful contraction toward the shortest valid result.

INVESTIGATION AUTHORIZED

Begin the Investigation

You have been introduced to the Minimum Window Substring problem, its available evidence, its central difficulty, and the reasoning methodology that will guide the investigation.

The investigation begins by establishing the Base Component and defining the required answer. From there, the character requirements will determine what constitutes complete coverage.

The Scanner examines the source string. The active boundaries define the current candidate. The Recorder preserves the count-sensitive evidence needed to evaluate coverage.

Every contraction must be justified. A shorter candidate is useful only when it continues to satisfy every character requirement.

The investigation must ultimately establish how to preserve the shortest valid result—or prove that no valid result exists.

THE EVIDENCE COMES BEFORE THE CODE.
Begin Case File Investigation