Trains the technique from
LeetCode 2592Maximize Greatness of an ArrayThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A list of whole numbers reads values. Rearrange the same values into any order you like and lay the rearrangement alongside the original.
A position betters the original when the rearrangement's value there is strictly larger than the original's.
Return the most positions that can be made to better the original at once.
Example 1
Every value is the same, so no rearrangement puts a larger value anywhere.
Example 2
The two twos can be laid over the two ones, bettering both of those positions, but nothing is left to better a two.
Example 3
Shifting every value one place along leaves each position holding the next value up, which betters all but one.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def maximize_greatness(values: list[int]) -> int:public int maximizeGreatness(int[] values)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.