Minimum Window of Required Words
Updated
Problem statement
Given a space-separated string text and an array requiredWords, return the shortest contiguous sequence of words that contains every required occurrence.
If a word appears multiple times in requiredWords, the returned window must contain it at least that many times. If several windows have the same minimum length, return the earliest one. If no qualifying window exists, return the empty string.
Function
minimumRequiredWordWindow(text: String, requiredWords: String[]) → StringExamples
Example 1
text = "the quick brown fox jumps over the lazy dog"requiredWords = ["fox","dog"]return = "fox jumps over the lazy dog"The only window containing both required words starts at fox and ends at dog.
Example 2
text = "a b a c b a"requiredWords = ["a","a","b"]return = "a b a"The first three words contain two occurrences of a and one of b. No two-word window can satisfy the multiplicities.
Constraints
1 <= text.length <= 200000textcontains lowercase English words separated by exactly one space.1 <= requiredWords.length <= 20000- Every required word is a non-empty lowercase English word.
- Matching is case-sensitive.
More Salesforce Phone Screen questions
- Detect a Cycle in a Linked ListPHONE SCREEN · Seen Oct 2026
- Find Rows Common to Two TablesPHONE SCREEN · Seen Oct 2026
- Merge Two Sorted Linked ListsPHONE SCREEN · Seen Oct 2026
- Permutations of Unique CharactersPHONE SCREEN · Seen Aug 2026
- Minimum Window SubstringPHONE SCREEN · Seen Aug 2026
- Optimal Account BalancingPHONE SCREEN · Seen Jul 2026
- Longest Increasing SubsequencePHONE SCREEN · Seen Jul 2026
- Maximal SquarePHONE SCREEN · Seen Jul 2026
- ATM Queue Exit OrderPHONE SCREEN · Seen May 2026
- Good Ways to Split an ArrayPHONE SCREEN · Seen May 2026
Similar questions at other companies
- Longest Substring Without Repeating CharactersAngel One · PHONE SCREEN
- Longest Substring Without Repeating CharactersNykaa · PHONE SCREENNykaa interview questions
- Longest Substring Without Repeating CharactersIBM · PHONE SCREENIBM interview questions
- Longest Substring Without Repeating CharactersTikTok · PHONE SCREENTikTok interview questions
- Find Word-Multiset WindowsAmazon · PHONE SCREEN
- Find the First Contiguous HaikuFaire · PHONE SCREEN
- Longest Substring Without Repeating CharactersCapgemini · PHONE SCREENCapgemini interview questions
- Longest Substring Without Repeating CharactersWex · PHONE SCREEN
- Longest Substring Without Repeating CharactersRedNote · PHONE SCREEN
- Longest Substring Without Repeating CharactersNetflix · PHONE SCREENNetflix interview questions