← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Meta SWE coding round, one question the whole session. Classic array problem but the two-pointer angle is easy to miss if you're not warmed up.

Questions Asked (1)

Q1

Given an array of heights representing vertical lines, find two lines that form a container with the x-axis holding the maximum amount of water. Return that maximum volume.

Algorithms & Data Structures
Author's notes

Started with brute force because I panicked a little and wanted to show I understood the problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and constraints, then propose a brute-force O(n^2) solution as a baseline. Follow up with an optimal two-pointer approach that starts with the widest container and moves the pointer at the shorter line inward, achieving O(n) time and O(1) space. Explain why this greedy strategy works and walk through a small example.

Pro tip: Emphasize that the two-pointer approach is optimal because moving the taller line can never increase the area, as the width decreases and the height is limited by the shorter line. This demonstrates deep understanding and avoids unnecessary complexity.

1. Clarify the problem

Restate the problem to ensure understanding: given an array of heights, find two lines that together with the x-axis form a container holding the most water. Confirm that the container cannot be slanted and that the lines are vertical.

2. Discuss brute force

Mention that a brute-force solution would check all pairs of lines, calculating the area as min(height[i], height[j]) * (j - i). This takes O(n^2) time, which is inefficient for large inputs.

3. Introduce two-pointer approach

Propose using two pointers, one at the beginning and one at the end. Calculate the area, then move the pointer pointing to the shorter line inward. Repeat until the pointers meet.

4. Explain correctness

Justify why moving the shorter line is safe: the area is limited by the shorter line, and moving the taller line would only decrease the width without increasing the height. Thus, the maximum area is not missed.

5. Analyze complexity and edge cases

State that the two-pointer approach runs in O(n) time and O(1) space. Discuss edge cases like arrays with fewer than two elements, all equal heights, or strictly increasing/decreasing heights.

Key Points to Mention

  • Area formula: min(height[i], height[j]) * (j - i)
  • Two-pointer technique starting from widest container
  • Greedy choice: always move the pointer at the shorter line
  • Proof of optimality: moving the taller line cannot yield a larger area
  • Time complexity: O(n) vs O(n^2) brute force
  • Space complexity: O(1) extra space

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