← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Meta SWE coding round with a classic array traversal problem. The ocean buildings question sounds easy but the follow-up variations are where they really dig in.

Questions Asked (1)

Q1

Given an array of building heights facing the ocean on the right, return the indices of buildings that can see the ocean (no strictly taller building to their right), in increasing order. Solve it in O(n) and then discuss variations like leftward views or non-strict height comparisons.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The core idea clicked fast: scan right to left, track the running max, any building taller than the current max makes the cut.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and edge cases, then propose an O(n) solution using a right-to-left scan while tracking the maximum height seen so far. After implementing, discuss variations like leftward views and non-strict comparisons, explaining how the algorithm adapts.

Pro tip: Emphasize that the right-to-left scan is optimal because it processes each building once, and mention that the same pattern applies to many 'next greater element' problems. Also, proactively discuss trade-offs between strict and non-strict comparisons to show depth.

1. Clarify the problem and edge cases

Ask clarifying questions about input constraints, whether heights can be equal, and if the output should be sorted. Confirm that a building can see the ocean if no strictly taller building exists to its right.

2. Propose an O(n) algorithm

Explain a right-to-left scan: initialize max_height to -infinity and an empty list. Iterate from the last building to the first, and if the current height is greater than max_height, add its index to the list and update max_height.

3. Implement and test

Write clean code for the algorithm, then walk through a small example to verify correctness. Mention that the list will be in decreasing order of indices, so reverse it to get increasing order.

4. Analyze complexity

State that the time complexity is O(n) because each building is visited once, and space complexity is O(k) where k is the number of visible buildings (or O(1) extra space excluding output).

5. Discuss variations and trade-offs

Explain how to adapt the algorithm for leftward views (scan left-to-right) and for non-strict comparisons (use >= instead of >). Discuss implications, such as equal-height buildings seeing the ocean in non-strict mode.

Key Points to Mention

  • Right-to-left scan with a running maximum height.
  • Time complexity O(n) and space complexity O(k) for output.
  • Handling of equal heights: strict vs non-strict comparison.
  • Reversing the result to get indices in increasing order.
  • Adaptation for leftward views by scanning from left to right.
  • Edge cases: empty array, single building, all buildings same height.

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