← Questions

Longest vacation with N PTO days

0
MetaCodingLast asked Nov 2025

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 — calendar is a string of W and H. 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) <= 365 here, but the method should work for long inputs.
  • 0 <= pto <= len(calendar). Unused days off are fine.

Clarifying questions

  • Must all pto days be used, or at most pto?
  • 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 pto workdays: extend the right end, shrink from the left while the window has too many W, and record the longest window.
  • Why the window is valid: covering every workday inside it uses at most pto days.
  • O(n) time, O(1) space.
  • Edge cases: pto = 0, pto at 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

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