← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Meta SWE coding round, one sliding window problem about maximizing vacation days by converting workdays to holidays with a fixed PTO budget. Pretty clean problem once you see it, but I second-guessed myself on the edge cases more than I should have.

Questions Asked (1)

Q1

Given a string of 'H' (holiday) and 'W' (workday) characters and an integer PTO, find the length of the longest contiguous subarray where the number of 'W' days is at most PTO.

Algorithms & Data Structures
Author's notes

Classic sliding window once you reframe it: you're just looking for the longest window with at most PTO occurrences of 'W'.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a sliding window (two-pointer) technique to maintain a window with at most PTO 'W' characters, expanding the right pointer and shrinking the left when the count exceeds PTO. Track the maximum window length seen. This yields an O(n) time and O(1) space solution.

Pro tip: Clarify edge cases upfront (e.g., PTO >= total W's, empty string) and mention that the sliding window works because the constraint is monotonic: adding characters can only increase W count, so shrinking is safe.

1. Understand the problem

Restate the problem: find the longest contiguous substring where the number of 'W' characters is ≤ PTO. Confirm input/output and edge cases.

2. Choose the algorithm

Select sliding window because it efficiently finds the longest subarray satisfying a monotonic constraint. Explain why brute force is O(n^2) and less optimal.

3. Implement the sliding window

Initialize left=0, w_count=0, max_len=0. Iterate right from 0 to n-1: if s[right]=='W', increment w_count. While w_count > PTO, if s[left]=='W', decrement w_count; increment left. Update max_len = max(max_len, right-left+1).

4. Analyze complexity

Time complexity O(n) because each character is visited at most twice (by right and left pointers). Space complexity O(1) as only a few variables are used.

5. Test with examples

Walk through a small example (e.g., 'HWWWH', PTO=1) to verify correctness. Also test edge cases: all 'H', all 'W', PTO=0, PTO >= total W's.

Key Points to Mention

  • Sliding window (two-pointer) technique for O(n) time and O(1) space.
  • Maintain a count of 'W' characters in the current window.
  • Shrink the window from the left when the count exceeds PTO.
  • Track the maximum window length seen so far.
  • Handle edge cases: empty string, PTO=0, PTO >= total W's.
  • Explain why the sliding window is valid: the constraint is monotonic (adding characters only increases W count).

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