← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Did a coding round at Meta for a software engineer role. One question, sliding window, nothing too wild but the details matter more than you'd expect.

Questions Asked (1)

Q1

Given a binary array and an integer k, find the maximum number of consecutive 1s you can get if you're allowed to flip at most k zeros.

Algorithms & Data Structures
Author's notes

The sliding window click took me a second longer than I'd like to admit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a sliding window (two-pointer) technique to maintain a window that contains at most k zeros. Expand the right pointer to include new elements, and when the number of zeros exceeds k, shrink the window from the left until the zero count is within k. Track the maximum window length throughout.

Pro tip: Clarify that the array is binary and that flipping zeros to ones is equivalent to finding the longest subarray with at most k zeros. Mention that the solution runs in O(n) time and O(1) space, which is optimal.

1. Understand the problem

Restate the problem: find the longest contiguous subarray that contains at most k zeros, since flipping those zeros yields consecutive 1s. Confirm that the array is binary and k is non-negative.

2. Choose the sliding window approach

Explain that a sliding window with two pointers (left and right) efficiently tracks a window with at most k zeros. Initialize left = 0, zero_count = 0, and max_length = 0.

3. Expand and contract the window

Iterate right from 0 to n-1: if the current element is 0, increment zero_count. While zero_count > k, if the element at left is 0, decrement zero_count, then increment left. Update max_length with the current window size (right - left + 1).

4. Return the result

After the loop, max_length holds the maximum number of consecutive 1s achievable by flipping at most k zeros. Return max_length.

5. Analyze complexity

State that the time complexity is O(n) because each element is visited at most twice (once by right, once by left), and space complexity is O(1) as only a few variables are used.

Key Points to Mention

  • Sliding window technique with two pointers
  • Maintaining a count of zeros within the window
  • Condition to shrink the window when zero count exceeds k
  • Updating the maximum window length
  • Time complexity O(n) and space complexity O(1)
  • Edge cases: k >= number of zeros (return entire array length), empty array, all ones

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