Site Message

Only Premium Users can view the Question

Question: Zoho | On-Campus OA 2026 | Visible Towers | Server Clusters | HackerRank Coding Assessment | Complete Solutions & Tips | Data Tracking Arrays & Tree Traversal | Mar 15th Campus Assessment
0
Entering edit mode

Question 1: Visible Towers

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]:

  • Tower 1 (height 5) can see towers 2 and 3.
  • Tower 2 (height 2) can see towers 1 and 3.
  • Tower 3 (height 10) can see all other towers.
  • Tower 4 (height 1) can see only tower 3.

The function should return[2, 2, 3, 1].

Function Description:Complete the functioncountVisibleTowersin the editor with the following parameters:

  • int height[n]: an array of integers representing the height of each tower.

Returns:

  • int[n]: the total number of towers visible from each tower.

Constraints:

  • 1 <= n <= 10^5
  • 1 <= height[i] <= 10^9

 


Question 2: Server Clusters

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.

  • The server at vertex 0 is not connected to any other server, so the cluster containing it has a size of 1.
  • The server at vertex 1 is connected to the server at vertex 2, and 2 is connected only to 1, forming a cluster of size 2.
  • The server at vertex 2 is connected to the server at vertex 1, and 1 is connected only to 2, forming a cluster of size 2.

Hence, the answer returned is[1, 2, 2].

Function Description:Complete the functiongetClusterSizesin the editor with the following parameters:

  • serverProp[n]: the properties of servers that determine server connectivity.

Returns:

  • int[n]: the total size of the cluster to which each server belongs.

Constraints:

  • 1 <= n <= 10^5

 

Login before adding your answer.

Similar Posts
Loading Similar Posts