← Questions
Longest vacation with N PTO days
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Meta's technical phone screen, last asked Nov 2025. It tests sliding window and arrays.
A year is a sequence of days, each a workday (W) or a holiday (H). You may spend up to pto days of paid time off, each turning one workday into a day off. Return the length of the longest run of consecutive days off you can make.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
longest_vacation(calendar: str, pto: int) -> int—calendaris a string ofWandH. Returns the longest streak of days that are holidays or covered workdays.
Example
longest_vacation("WHHWWHW", 2) -> 5 # cover days 3 and 4 (0-based): H H W W H becomes 5 days off
longest_vacation("WWW", 1) -> 1
longest_vacation("HWH", 0) -> 1
longest_vacation("WWHW", 0) -> 1
Constraints
-
1 <= len(calendar) <= 365here, but the method should work for long inputs. -
0 <= pto <= len(calendar). Unused days off are fine.
Clarifying questions
- Must all
ptodays be used, or at mostpto? - Do weekends count as holidays, or are they already in the calendar?
- Should I also return where the vacation starts?
- Does the calendar wrap from December into January?
What a strong answer covers
- A sliding window that holds at most
ptoworkdays: extend the right end, shrink from the left while the window has too manyW, and record the longest window. - Why the window is valid: covering every workday inside it uses at most
ptodays. - O(n) time, O(1) space.
- Edge cases:
pto = 0,ptoat least the number of workdays, a calendar with no holidays.
Follow-ups
- Return the start and end dates of the best vacation.
- The calendar wraps around the year (the last days of December join the first days of January).
- Several people with different calendars want one shared vacation.
Where it's asked
- Meta · Technical phone screen · Last asked Nov 202545 min · Two coding problems in CoderPad, about 20 minutes each · Usually no AI; some newer screens are AI-assisted
What it tests
sliding window · arrays
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
