Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

36. Minimum Window Substring

HardDay 11 of 60Sliding Window

Given strings s and t, return the shortest substring of s that contains every character of t, counting repeats (if t has two as, the substring needs at least two as). If no such substring exists, return the empty string "". The answer is unique for the given tests.

Example 1
Input: s = "ADOBECODEBANC", t = "ABC"
Output: "BANC"
"BANC" holds one A, one B and one C, and no shorter window does.
Example 2
Input: s = "a", t = "aa"
Output: ""
t needs two as but s has only one.
Constraints
  • 1 <= s.length, t.length <= 10^5
  • Both strings contain uppercase and lowercase English letters
Hints
Frequently asked at: Meta, Amazon, Google, LinkedIn, Uber
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min