FastPrepMinimum Window of Required Words
Problems/Minimum Window of Required Words

Minimum Window of Required Words

Salesforce logoSalesforce● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Salesforce phone screen. The report does not say how repeated words count or how to break a tie between windows of equal length. Our version is about 96% the same as the reported question.

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[]) → String

Examples

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 <= 200000
  • text contains 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

Salesforce interview experiences

  • Salesforce Infrastructure SWE OA and Onsite: 1 Experience
  • Salesforce Experienced Backend SWE First Round: 1 Experience
All Salesforce interview questionsSee Salesforce hiring insights
Saved
class Solution {
    public String minimumRequiredWordWindow(String text, String[] requiredWords) {
        // Write your code here.
    }
}
Checking account…