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
Returns (int) 4

Example 2

Input
s (string) = a
t (string) = aa
Returns (int) 0

Example 3

Input
s (string) = abdabca
t (string) = abc
Returns (int) 3

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

Ready to test your solutionRun Code checks your solution against the test cases.Shift + Enter to run

Notifications

Updates are enabled for this browser.

Receive new tutorials, articles and learning resources. You can turn updates off anytime.

Test browser code

Use this code in admin to send a test notification to this browser.