FastPrepMinimum Window Substring

Minimum Window Substring

LinkedIn logoLinkedIn● HardFULLTIMEONSITE INTERVIEW
Learn

Problem statement

Given strings s and t, return the shortest contiguous substring of s that contains every character of t, including repeated characters with their required multiplicities.

If no such substring exists, return the empty string. If several valid windows have the same minimum length, return the one that starts earliest in s.

Function

minWindow(s: String, t: String) → String

Examples

Example 1

s = "ADOBECODEBANC"t = "ABC"return = "BANC"

BANC is the shortest window containing A, B, and C.

Example 2

s = "a"t = "aa"return = ""

The source string does not contain two copies of a.

Example 3

s = "abdcab"t = "ab"return = "ab"

Two length-two windows qualify, so the earlier one is returned.

Constraints

  • 1 <= s.length, t.length <= 10^5.
  • s and t contain ASCII letters and digits.

More LinkedIn problems

See LinkedIn hiring insights
public String minWindow(String s, String t) {
    // Write your solution here.
}
s"ADOBECODEBANC"
t"ABC"
expected"BANC"
Checking account…