← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Meta coding screen for a software engineer role, one problem the whole time. Sliding window stuff, which I thought I knew cold until I actually had to code it under pressure.

Questions Asked (1)

Q1

Given a year represented as an array of 'H' (Holiday) and 'W' (Workday) characters, and an integer representing the number of PTO days available, find the longest contiguous stretch of days you can take off. Each 'W' day in the window costs one PTO day; 'H' days are free.

Algorithms & Data Structures
Author's notes

Sliding window with a counter for W's inside the window.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Recognize this as a sliding window problem where you expand a window and shrink it when the number of 'W' days exceeds the PTO budget. Use two pointers to maintain the longest valid window in O(n) time, and clearly explain why the window is valid and how you update the maximum length.

Pro tip: Before coding, clarify edge cases like empty array, PTO greater than total workdays, or all holidays; mentioning these shows thoroughness and can prevent bugs. Also, explicitly state the time and space complexity and why the sliding window is optimal compared to brute force.

1. Clarify the problem and edge cases

Confirm that the array represents consecutive days and that you can only take one contiguous stretch. Ask about edge cases: empty array, PTO=0, PTO >= total 'W' days, and whether the year wraps around (usually not).

2. Identify the optimal approach

Recognize that this is a longest subarray with at most K zeros (where 'W' is 0 and 'H' is 1) problem. Explain that a sliding window (two pointers) achieves O(n) time and O(1) space, which is optimal.

3. Walk through the sliding window algorithm

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

4. Analyze complexity and test with examples

State that time complexity is O(n) because each element is visited at most twice, and space is O(1). Test with a small example like ['W','H','W','W','H'] and PTO=1 to verify the window logic.

5. Discuss potential follow-ups

Be prepared to discuss variations: if PTO can be used non-contiguously, if the year is circular, or if you need to return the actual stretch of days. Mention that the same sliding window can be adapted.

Key Points to Mention

  • Sliding window technique with two pointers for O(n) time complexity
  • Mapping 'W' to cost 1 and 'H' to cost 0, so the problem becomes longest subarray with sum <= PTO
  • Maintaining a running count of 'W' days in the current window and shrinking when it exceeds PTO
  • Updating the maximum length after each expansion
  • Edge cases: empty array, PTO=0, PTO >= total workdays, all holidays
  • Time and space complexity analysis: O(n) time, O(1) space

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