Question: Write a Java program for below problem and please provide fresh solution and complete code. You are given an array A of N integers, representing
Write a Java program for below problem and please provide fresh solution and complete code.
You are given an array A of N integers, representing the maximum heights of N skyscrapers to be built.
Your task is to specify the actual heights of the skyscrapers, given that:
the height of the Kth skyscraper should be positive and not bigger than AK;
no two skyscrapers should be of the same height;
the total sum of the skyscrapers' heights should be the maximum possible.
Write a function:
class Solution public int solutionint A;
that, given an array A of N integers, returns an array B of N integers where BK is the assigned height of the Kth 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.
Examples:
Given A your function should return as all of the skyscrapers may be built to their maximum height.
Given A your function may return Note that is also a valid answer. It is not possible for the last two skyscrapers to have the same height. The of height of one of them should be and the other should be
Given A your function should return
Write an efficient algorithm for the following assumptions:
N is an integer within the range ;
each element of array A is an integer within the range ;
there is always a solution for the given input.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
