← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026Remote

Summary

Second problem in a Meta SWE phone screen loop, and it was the one that apparently filters most people out. The sliding window stuff sounds manageable until you're actually writing it under pressure.

Questions Asked (1)

Q1

Given two strings s and t, find the shortest substring of s that contains all characters of t (including duplicates). Return an empty string if no such substring exists.

Algorithms & Data Structures
Author's notes

The part that tripped me up wasn't the expand-right logic, it was the matched counter.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a sliding window (two pointers) to expand and contract a window over s while tracking character counts of t. Maintain a count of matched characters to know when the window is valid, and record the minimum length window that contains all characters of t.

Pro tip: Clarify edge cases upfront (e.g., t longer than s, empty strings) and mention that the algorithm runs in O(n + m) time, which is optimal. Also, discuss how you would handle Unicode characters if relevant.

1. Clarify requirements and edge cases

Confirm that the substring must contain all characters of t including duplicates, and that order does not matter. Discuss edge cases: t longer than s, empty strings, or no valid substring.

2. Choose the sliding window approach

Explain that a brute-force check of all substrings is O(n^2 * m), but a sliding window with character frequency maps achieves O(n + m). Use two pointers to represent the window boundaries.

3. Expand the window to find a valid substring

Move the right pointer to include characters, updating a frequency map of the current window. Track how many characters from t are fully matched (i.e., window count >= required count).

4. Contract the window to find the minimum

Once all characters are matched, move the left pointer to shrink the window while it remains valid. Update the minimum length and starting index whenever a smaller valid window is found.

5. Return the result and analyze complexity

After the right pointer reaches the end, return the substring using the recorded start and min length, or empty string if none. State time complexity O(n + m) and space O(m) for the frequency maps.

Key Points to Mention

  • Sliding window technique with two pointers
  • Character frequency maps (hash maps or arrays) for t and the current window
  • Tracking the number of matched characters to efficiently check window validity
  • Time complexity O(n + m) and space complexity O(m)
  • Handling duplicates correctly by comparing counts
  • Edge cases: no valid substring, t longer than s, empty strings

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.