BackmediumArrays PhonePe

Reconstruct Tower from Reflections Solution

Problem Statement

The manager of a tower construction company wants to analyze the tower structure. He has a list of floor numbers where the reflection of the floor was visible from a bird's-eye view. Help the manager to reconstruct the maximum height of the tower and its possible configurations from these reflections. The output should be a string in the format 'The maximum height of the tower is X because the first floor number is Y and the last floor number is Z.'

Example 1
Input
[1, 2, 3, 4, 5]
Output
The maximum height of the tower is 5 because the first floor number is 1 and the last floor number is 5.

Explanation: Step-by-step: with input [1, 2, 3, 4, 5], we can determine that the maximum height of the tower is 5 because the first floor number is 1 and the last floor number is 5. The possible configurations are the numbers from 1 to 5.

Example 2
Input
[1, 3, 5, 7]
Output
The maximum height of the tower is 7 because the first floor number is 1 and the last floor number is 7.

Explanation: Step-by-step: with input [1, 3, 5, 7], we can determine that the maximum height of the tower is 7 because the first floor number is 1 and the last floor number is 7. The possible configurations are the numbers from 1 to 7, but only the odd numbers are present in the input.

Constraints

  • 1 ≤ floorNumbers.length ≤ 10^5
  • 1 ≤ floorNumbers[i] ≤ 10^6
  • The floor numbers in the reflection list may or may not be present in their original order
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free