← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Meta SWE coding round with a sliding window string problem. Pretty standard algorithmic stuff but the constraint on O(n) complexity is what makes it interesting.

Questions Asked (1)

Q1

Given a string, find the length of the substring with the greatest number of unique characters. Must run in O(n) time. String is lowercase letters only, up to 100k characters.

Algorithms & Data Structures
Author's notes

The examples are a bit sneaky.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a sliding window with two pointers to maintain a window of unique characters, expanding the right pointer and shrinking the left when a duplicate is found. Track the maximum window length seen. This runs in O(n) time because each character is visited at most twice.

Pro tip: Clarify the problem statement first: if the string contains all unique characters, the answer is the entire string length. Also, mention that the sliding window approach is optimal and handles the 100k constraint efficiently.

1. Clarify and Confirm

Restate the problem to ensure understanding: find the longest substring without repeating characters. Confirm constraints: lowercase letters, length up to 100k, O(n) required.

2. Choose Data Structures

Use a hash set or a fixed-size array (size 26) to track characters in the current window. A set is simpler; an array is faster and uses less memory.

3. Implement Sliding Window

Initialize left and right pointers at 0, and max_length = 0. Expand right, adding characters to the set. If a duplicate is found, shrink the window by moving left and removing characters until the duplicate is gone.

4. Update and Return

After each expansion, update max_length with the current window size. Continue until right reaches the end, then return max_length.

5. Analyze Complexity

Explain that each character is processed at most twice (once by right, once by left), so time is O(n). Space is O(1) since the alphabet is fixed at 26.

Key Points to Mention

  • Sliding window technique with two pointers
  • Use of a set or boolean array to track characters in the window
  • Time complexity O(n) and space complexity O(1)
  • Handling edge cases: empty string, all unique characters, all same characters
  • Optimization: using an array of size 26 instead of a hash set for faster access
  • The algorithm processes each character at most twice, ensuring linear time

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