Sliding window with a counter for W's inside the window.
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.
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).
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.
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).
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.
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.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.