FastPrepShortest Window Covering All Letters
Problems/Shortest Window Covering All Letters

Shortest Window Covering All Letters

Adobe logoAdobe● HardFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: An Adobe first round had three coding questions, two medium and one hard. This minimum window substring task was one of them, named in the report only by a link, and the report does not say which question was the hard one.

The report gives no limits or examples and no rule for ties. Here the strings hold English letters with case mattering, each is up to 10^4 long, repeats in t must be matched, ties go to the leftmost window and no window gives "". The examples are our own.

The judged task matches the report at about 95%.

You are given two strings s and t. Find the shortest stretch of consecutive characters of s that contains every letter of t, counting repeats: if t has a letter twice, the stretch needs it at least twice.

  • If several shortest stretches exist, return the one that starts furthest to the left.
  • If no stretch works, return the empty string "".

Function

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

Examples

Example 1

s = "xyyzyzyx"t = "xyz"return = "zyx"

The shortest stretches holding an x, a y and a z have length 3. Checking from the left, the first one is "zyx" at the end (indexes 5 to 7); every earlier stretch of length 3 misses at least one of the three letters (for example "xyy" has no z, and "yyz" has no x).

Example 2

s = "bAaAb"t = "AA"return = "AaA"

t needs two uppercase As. The lowercase a does not count, so the shortest stretch is "AaA" (indexes 1 to 3).

Example 3

s = "abc"t = "d"return = ""

No stretch of s holds a d, so the answer is the empty string.

Constraints

  • 1 <= s.length, t.length <= 10^4
  • s and t contain only English letters (uppercase and lowercase are different letters).

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public String smallestCoveringWindow(String s, String t) {
    // Write your code here.
}
Checking account…