#3301
Maximize the Total Height of Unique Towers
medium · 37.3% accepted · 129 likes · top 15%
Description
You are given an array maximumHeight, where maximumHeight[i] denotes the maximum height the ith tower can be assigned.
Your task is to assign a height to each tower so that:
- The height of the ith tower is a positive integer and does not exceed maximumHeight[i].
- No two towers have the same height.
Return the maximum possible total sum of the tower heights. If it's not possible to assign heights, return -1.
Solution