Visible Towers
Updated
Problem statement
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
visibleTowers(height: int[]) → int[]
Complete the function visibleTowers in the editor.
visibleTowers has the following parameter:
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.
Examples
Example 1
height = [5, 2, 10, 1]return = [2, 2, 3, 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].
Constraints
f🍋🍋
More Salesforce interview questions
- Count Subarrays With Product Equal to KOA · Seen Dec 2026
- Get Minimum TimeOA · Seen Nov 2026
- Count Increasing TripletsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Reverse a Sublist of a Linked ListONSITE INTERVIEW · Seen Nov 2026
- Rotting OrangesONSITE INTERVIEW · Seen Nov 2026
- 3Sum SmallerONSITE INTERVIEW · Seen Nov 2026
- Count Zero Request ServersONSITE INTERVIEW · Seen Nov 2026
- Minimum No-Repeat Segments After One Character RemovalOA · Seen Nov 2026
- Get Message StatusOA · Seen Nov 2026
Similar questions at other companies
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Sum of Subarray MinimumsNVIDIA · OANVIDIA interview questions
- Shopkeeper Final Price SummaryMicrosoft · OAMicrosoft interview questions
- Nested Recipe Blocks (Game Adaptation)Roblox · OARoblox interview questions
- Maximum Capped Histogram Area After One RemovalMyntra · OAMyntra interview questions
- Steps to the Next Higher Value in a CircleRippling · OARippling interview questions
- Shopkeeper Final PriceUber · OAUber interview questions
- Predict AnswerAmazon · OA
- Retention Policy CollisionBox · OABox interview questions
- Longest Prefix-Valid Binary SubarrayHackerRank · OAHackerRank interview questions