Math
3723. Maximize Sum of Squares of Digits
Sum of squares is convex, and that one fact settles the problem. Take two digits a <= b with room to move, shift a single unit from a up to b, and the score changes by 2(b - a) + 2, which is always positive. So no best answer keeps digits in the middle: push units upward until every digit is pinned at 9 or at 0, with at most one leftover sitting in between.
Loading…