Meta Interview Coding Question: Ocean View Buildings and Grid Pathfinding

16 Views
No Comments

Description

You are given an array of integers that represent the height of apartment buildings.

The leftmost building is at index 0, and the array lists the buildings from left to right. After the rightmost building, there is the ocean.

Buildings are of the same width and arranged in a straight line from left to right toward the ocean.

Return the indexes of the buildings that have an ocean view.

Example:

Input: [4, 3, 2, 3, 1]
Output: [0, 3, 4]

You are also given a game board represented as a 2D array of zeroes and ones.

0 stands for passable positions, and 1 stands for impassable positions.

Design an algorithm to find a path from the top-left corner to the bottom-right corner.

For example, for the following board:

entrance ->
0 0 0 0 0 0 0
0 0 1 0 0 1 0
0 0 1 0 1 1 0
0 0 1 0 1 0 1
1 1 1 0 0 0 0 -> exit

A possible path is:

entrance ->
+ + + + 0 0 0
0 0 1 + 0 1 0
0 0 1 + 1 1 0
0 0 1 + 1 0 1
1 1 1 + + + + -> exit

Assuming a zero-indexed grid of rows and columns, with (0, 0) at the top-left corner (entrance).

This question combines two classic interview patterns. The first part is the ocean-view buildings problem: scan the array from right to left, keep track of the tallest building seen so far, and collect every index whose height is strictly greater than that maximum. The second part is a grid pathfinding problem on a binary matrix, where 0 means walkable and 1 means blocked; the goal is to determine whether a path exists from the top-left to the bottom-right corner using DFS or BFS with a visited set. Together, they test array traversal, boundary handling, and basic graph search skills.

END
 0