Use a sliding window to find the longest subarray with at most n 'w's. Expand the right pointer, count workdays, and shrink from the left when the count exceeds n. Track the maximum window length.
Pro tip: Clarify that 'consecutive days off' means consecutive days in the array where you either already have a holiday or convert a workday to a holiday. Mention that the window can include both 'h' and converted 'w's.
Confirm that you can convert at most n workdays to holidays, and you want the longest contiguous segment of days that are all holidays (original or converted).
Recognize that the problem reduces to finding the longest subarray with at most n 'w's. The window represents a candidate segment of consecutive days off.
Initialize left and right pointers at 0, a workday count, and max length. Expand right, increment workday count if the character is 'w'. While workday count > n, shrink from left (decrement count if left character is 'w') and increment left. Update max length with right - left + 1.
Time complexity is O(m) where m is the array length, since each element is visited at most twice. Space complexity is O(1) as only a few variables are used.
Walk through a small example, e.g., ['w','h','w','w','h'] with n=1, to verify the window expands and shrinks correctly and returns the expected maximum.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.