Question: Cognizant, Online Assessments in 03 Jun, 2025 | Tall Buildings Sum | Array Indexing | Cognizant On-campus 2025 | OA 2025
0
Entering edit mode

Question 1: Tall Buildings Sum

Problem Statement:

You are given an integer array H representing the heights of N buildings on a street, and an integer value D. A building at index i is considered tall if its height is strictly greater than the heights of the buildings at indices (i - D) and (i + d) (if those indices exist).

If neither or any one of these indices exists, the building is still considered tall. Your task is to find and return an integer value representing the total sum of the heights of all the tall buildings.

Input Specification:

  • input1: An integer value N, representing the number of buildings.

  • input2: An integer array H, representing the heights of buildings.

  • input3: An integer value D.

Output Specification:

  • Return an integer representing the total height of all the tall buildings.

Example 1:

  • input1: 6

  • input2: {1, 3, 2, 1, 5, 4}

  • input3: 2

ADD COMMENTlink 7 hours ago Rohit • 30

Login before adding your answer.

Similar Posts
Loading Similar Posts