← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Meta SWE coding round with a classic array problem. Nothing too crazy but the edge cases will get you if you're not careful.

Questions Asked (1)

Q1

Given an array of house heights, return the indices of all houses that have an ocean view. A house has an ocean view if no house to its right is taller or equal in height.

Algorithms & Data Structures
Author's notes

Went with a right-to-left scan, tracking the max height seen so far.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem and edge cases, then propose an O(n) solution by scanning from right to left while keeping track of the maximum height seen so far. Explain that a house has an ocean view if its height is strictly greater than the current maximum, then update the maximum.

Pro tip: Mention that the indices can be returned in any order, but if sorted order is required, you can reverse the result at the end. Also, discuss how the solution handles duplicates and edge cases like empty arrays.

1. Clarify the problem

Ask clarifying questions to ensure you understand the definition of 'ocean view' and the expected output format. Confirm whether indices should be sorted and how to handle edge cases.

2. Discuss brute force

Acknowledge that a naive O(n^2) solution exists by checking each house against all to its right, but note it's inefficient for large inputs.

3. Propose optimal approach

Explain the O(n) right-to-left scan: maintain the maximum height seen so far and collect indices where the current height exceeds this maximum.

4. Walk through an example

Trace the algorithm on a sample array to demonstrate correctness and show how the maximum updates.

5. Analyze complexity and edge cases

State time and space complexity, and discuss handling of empty arrays, single-element arrays, and duplicates.

Key Points to Mention

  • Time complexity: O(n) with a single pass
  • Space complexity: O(1) extra space (excluding output)
  • Right-to-left traversal to efficiently track the maximum
  • Strict inequality: a house must be taller than all to its right
  • Edge cases: empty array, single house, all equal heights
  • Output order: indices can be returned in any order unless specified

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