Question bank › Sliding Window
Dsa Sliding Window Hard

Minimum Substring to Cover All Words

You are given a list of words and a longer string `s`. Your task is to find the minimum length substring from `s` that contains all the words from the list at least once. If such a substring does not exist, return '' (an empty string). Input Format: The input consists of two lines. The first line contains an integer `n`, the number of words in the list. The second line contains `n` space-separated words, followed by the string `s` on the same line (after a space). Output Format: Output the minimum substring containing all the words, or '' if it does not exist. Example: Input: 4 this is a test a string this is a test string for our function Output: 'this is a test a string'

Key concepts

sliding_windowstringhashmap

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.