#C10676. Minimum Window Substring

    ID: 39907 Type: Default 1000ms 256MiB

Minimum Window Substring

Minimum Window Substring

Given two strings s and t, find the smallest contiguous substring of s that contains every character in t (including multiplicities). If no such substring exists, output an empty string.

The solution should be efficient, for instance using a sliding window approach combined with hash maps, and correctly handle cases with repeated characters.

For example:

  • Input: s = "ADOBECODEBANC", t = "ABC"; Output: "BANC"
  • Input: s = "a", t = "aa"; Output: ""
  • Input: s = "abcdebcabc", t = "abc"; Output: "abc"

inputFormat

The input is provided via standard input (stdin) and consists of two lines:

  1. The first line contains the string s.
  2. The second line contains the string t.

outputFormat

Output the smallest substring of s that contains all the characters of t (including multiplicities) via standard output (stdout). If no such substring exists, output an empty string.

## sample
ADOBECODEBANC
ABC
BANC