Buildings with an Ocean View
Updated
Problem statement
Given the heights of buildings in a row, find which buildings have an ocean view.
For this exercise, assume the ocean is to the right of the row. Building i has a view exactly when every building with index greater than i is strictly shorter. A building of equal or greater height blocks the view.
Return the zero-based indices of visible buildings in increasing order. The rightmost building always has a view. For this exercise, assume an empty row returns an empty array.
Function
findBuildings(heights: int[]) → int[]Examples
Example 1
heights = [6,2,5,3]return = [0,2,3]Indices 0, 2 and 3 are taller than every building to their right. Index 1 is blocked by the height-5 building.
Example 2
heights = [3,3,3]return = [2]Equal heights block each other, leaving only the rightmost index 2.
Example 3
heights = [1,2,4]return = [2]Each building except the last is blocked by a taller building to its right.
Example 4
heights = []return = []An empty row has no building indices.
Constraints
- For this exercise, assume
0 <= heights.length <= 2000and0 <= heights[i] <= 10^9.
More Meta Phone Screen questions
- Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
- First Element Greater Than KPHONE SCREEN · Seen Nov 2026
- Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
- Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
- Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026
- Deterministic K-Means AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Values Exclusive to the Current UserPHONE SCREEN · Seen Sep 2026
- First Bad Version in a Monotone ArrayPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Largest Number Below N from Reusable DigitsByteDance · PHONE SCREENByteDance interview questions
- Maximum Subarray Sum with One DeletionServiceNow · PHONE SCREENServiceNow interview questions
- Merchant Matching, Parts 1–2: Shared Fields and Weighted ThresholdsStripe · PHONE SCREENStripe interview questions
- Merge Sorted Squares of Two ArraysWhatNot · PHONE SCREENWhatNot interview questions
- Minimum Time to Spread Through a GridAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Interval List IntersectionsGrammarly · PHONE SCREEN
- Maximum Product of a Contiguous SubarrayLinkedIn · PHONE SCREENLinkedIn interview questions
- Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
- Design Hit CounterCharta Health · PHONE SCREENCharta Health interview questions
Meta interview experiences
- Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
- Meta Business Support Engineer Phone Screen: 1 Experience
- Meta Software Engineer Onsite Questions: 3 Experiences
- Meta AI Native Engineer OA and Onsite: 1 Experience
- Meta AI-Native Coding Interview: 3 Experiences
- Meta Production Engineer Intern Questions: 6 Experiences