Implement the method minimumWindowLength that returns the length of the smallest substring containing all required characters.

Find the shortest contiguous substring of s that contains every character of t, including repeated characters.

The task is designed to test careful handling of edge cases, not only the most common input.

  • Return 0 if no valid window exists.
  • Return the length, not the substring text.
  • Character frequency matters.
Example 1
Input:
s (string) = ADOBECODEBANC
t (string) = ABC
Return:
(int) 4
Example 2
Input:
s (string) = a
t (string) = aa
Return:
(int) 0
Example 3
Input:
s (string) = abdabca
t (string) = abc
Return:
(int) 3

Count required characters from t, expand the right side until valid, then shrink the left side while validity remains.

Run your code to see the result.