Smallest covering window
A free hard coding practice problem. Solve it in JavaScript, TypeScript or Python and check your solution against fresh hidden tests — edge cases and random inputs — as often as you like.
- Difficulty
- Hard
- Type
- Function
- Languages
- JavaScript, TypeScript or Python
Problem
Return the shortest substring of s that contains every character of t (with repeats: t = "aa" needs two a's). If several are equally short, return the leftmost; return "" if none exists. s can be 100,000 characters long.
Function signature
// JavaScript
function minWindow(s, t)
// TypeScript
function minWindow(s: any, t: any): any
// Python
def min_window(s, t):Examples
minWindow("ADOBECODEBANC", "ABC")→"BANC"minWindow("a", "aa")→""
How checking works
Run your code against the examples above, then submit a check: it runs on the server against hidden tests built fresh each time, including edge cases and random inputs. Practice is untimed and never affects a verified score; when you are ready, take a graded coding challenge to earn a badge.