Problem Β· Greedy
Skyscraper
Learn this problemProblem statement
You are gien an array A of N integers, representing the maximum heights of N skyscrapers to be built.
Your task if to specify the actual heights of the skyscrapers, given that:
Given an array A of N integers, returns an array B of N integers where B[K] is the assigned height of the K-th skyscraper satisfying the above conditions.
If there are several possible answers, the function may return any of them. You may assume that it is always possible to build all skyscrapers while fulfilling all the requirements.
Function
skyscraper(A: int[]) β int[]Examples
Example 1
A = [1, 2, 3]return = [1, 2, 3]As all of the skyscrapers may be built to their maximum height.
Example 2
A = [9, 4, 3, 7, 7]return = [9, 4, 3, 7, 6]Note that [9, 4, 3, 6, 7] is also a valid answer.
It is not possible for the last two skyscrapers to have the same height. The height of one of them should be 7 and the other should be 6.
Example 3
A = [2, 5, 4, 5, 5]return = [1, 2, 3, 4, 5]N/A
Constraints
N is an integer within the range [1..50,000]Each element of array A is an integer within the range [1..1,000,000,000]There is always a solution for the given inputMore Microsoft problems
- Maximum Pipeline ThroughputOA Β· Seen Jul 2026
- Maximum Strong Team SubarrayOA Β· Seen Jul 2026
- Minimum Cost K-Capable ModelsOA Β· Seen Jul 2026
- Alphabetically Smallest PalindromeOA Β· Seen Jul 2026
- Maximum Reward PointsOA Β· Seen Jul 2026
- Maximum Strength of Every NeuronOA Β· Seen Jul 2026
- Neural Network Subnetwork StrengthOA Β· Seen Jul 2026
- XOR MultiplicationOA Β· Seen Jul 2026