PayPal SDE 2 | DSA interview | Frontend
Anonymous User
338

DSA question-
There are n towers placed sequentially in the city of Hackerland. Tower xis visible from tower yif 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.

Example

There are n = 4 towers and height = [5, 2, 10, 1].

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).

Hope this helps someone.

Comments (1)