Skip to main content
All Questions

Find the shortest contiguous substring of a sentence containing all words of another string.

Unlock detailed company stats for this questionUpgrade

Given S1, a sentence, and S2, a string containing words, find the shortest contiguous substring of S1 that contains all the words in S2 (assume all S2 words appear in S1). Example: S1 = "this is a test string for test purposes", S2 = "test string purposes" gives "string for test purposes".

Community answers

No answers contributed by the community yet.

Related courses

Course

AI Engineering Interview Prep

Ace the AI engineering interview at top companies like Google, Anthropic, Meta, and OpenAI. Learn from detailed frameworks, example questions, and mock interviews with senior engineers. Practice system design, AI/ML concepts, AI-assisted coding, and behavioral rounds.

Course

Generative AI Interviews

Ace your interviews at AI-first and AI-powered companies. Learn to explain how Gen AI really works, where it fails, and how to use it responsibly. Understand how top tech companies build and deploy AI products and how generative AI works in production, from LLMs and RAG systems to real-world deployment.