Grokking Meta Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content
Buildings With an Ocean View (medium)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

You are given an array heights of size n, representing the heights of n buildings.

The ocean is to the right of these buildings. A building has an ocean view if there are no taller buildings to its right.

The task is to find the indices(0-based) of all such buildings with an ocean view.

Examples

  • Example 1:

    • Input: [4, 3, 2, 1]
    • Expected Output: [0, 1, 2, 3]
    • Justification: Each building is shorter than the one to its left, hence all have an ocean view.
  • Example 2:

    • Input: [2, 3, 1, 4]
    • Expected Output: [3]
    • Justification: Building at index 3 is the only one without taller buildings to their right.
  • Example 3:

    • Input: [7, 4, 3, 2, 1, 4, 6, 3]
    • Expected Output: [0, 6, 7]
    • Justification: Buildings at indices 0, 6, and 7 are the only ones without taller buildings to their right.

Constraints:

  • 1 <= heights.length <= 10<sup>5</sup>
  • 1 <= heights[i] <= 10<sup>9</sup>

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible