Only Premium Users can view the Question
Problem Statement:In Hackerland, there arentowers arranged in a sequence, each with a specific height. For each tower, determine how many other towers it can "see" both to its left and right. A towerican see another towerj(wherej != i) if all towers betweeniandjare shorter than towerj.
Example:Given towers with heights[5, 2, 10, 1]:
The function should return[2, 2, 3, 1].
Function Description:Complete the functioncountVisibleTowersin the editor with the following parameters:
Returns:
Constraints:
Problem Statement:Given an arrayserverProprepresenting the properties ofnservers, determine the size of the cluster to which each server belongs.
Two servers at indexesiandjare considered connected if the greatest common divisor (GCD) of their properties,serverProp[i]andserverProp[j], is greater than 1. Connected servers form clusters in the network.
Return an array of integers where theith value represents the size of the cluster to which theith server belongs.
Example:It is given thatn = 3,serverProp = [1, 2, 4]. Based on the given server properties, servers at indexes 1 and 2 are connected.
Hence, the answer returned is[1, 2, 2].
Function Description:Complete the functiongetClusterSizesin the editor with the following parameters:
Returns:
Constraints: