← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Meta SWE coding round, one question about buildings and sea views. Pretty classic stack problem once you figure out what they're actually asking.

Questions Asked (1)

Q1

Given an array representing building heights along a coastline, return the heights of all buildings that have an unobstructed view of the sea.

Algorithms & Data Structures
Author's notes

Took me a second to realize the sea is on one side and you scan from that direction.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem by asking which direction the sea is (left or right) and whether buildings with equal height block the view. Then propose a linear scan from the sea side, keeping track of the maximum height seen so far, and collect buildings that exceed this maximum.

Pro tip: After presenting the solution, mention that the same logic can be applied from both ends if the sea is on both sides, and discuss how to handle duplicates or equal heights based on the clarified rules.

1. Clarify requirements

Ask the interviewer to confirm the direction of the sea (e.g., left or right) and whether a building blocks the view if its height is equal to the current maximum. Also confirm if the output should be in any specific order.

2. Choose traversal direction

Decide to traverse from the sea side towards the land. For example, if the sea is on the left, start from the leftmost building and move right.

3. Track maximum height

Initialize a variable to keep track of the maximum height encountered so far. For each building, compare its height to this maximum.

4. Collect buildings with view

If the current building's height is greater than the maximum (or greater than or equal to, based on clarification), it has an unobstructed view. Add it to the result list and update the maximum height.

5. Return result

After traversing all buildings, return the list of heights. If the sea is on the right, either reverse the traversal or reverse the result to maintain the original order.

Key Points to Mention

  • Time complexity: O(n) single pass, space complexity: O(1) excluding output.
  • Handling edge cases: empty array, single building, all buildings same height.
  • Clarifying whether equal height blocks the view (strictly greater vs. greater than or equal).
  • Direction of the sea and how it affects traversal order.
  • Potential follow-up: what if the sea is on both sides? (Two passes, combine results).
  • Maintaining original order of buildings in the output if required.

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