FastPrepFastPrep
Problem Brief

Visible Towers

OA

There are n towers placed sequentially in the city of Hackerland. Tower x is visible from tower y if all towers between x and y have a height strictly less than that of x. For each tower, find the number of towers visible from this tower, both on the left and right side.

Function Description

Complete the function visibleTowers in the editor.

visibleTowers has the following parameter:

  1. int[] height: an array of integers representing the heights of the towers

Returns

int[]: an array of integers where the i-th element is the number of towers visible from the i-th tower.

1Example 1

Input
height = [5, 2, 10, 1]
Output
[2, 2, 3, 1]
Explanation

From tower 1, towers 2 and 3 are visible. From tower 2, towers 1 and 3 are visible. From tower 3, all 3 other towers are visible. From tower 4, tower 3 is visible.

Return [2, 2, 3, 1].

Constraints

Limits and guarantees your solution can rely on.

f🍋🍋
public int[] visibleTowers(int[] height) {
  // write your code here
}
Input

height

[5, 2, 10, 1]

Output

[2, 2, 3, 1]

Sign in to submit your solution.