Tap here to switch tabs
Problem
Submissions

Problem: Maximize Sum of Squares of Digits

Try to solve the Maximize Sum of Squares of Digits problem.

Statement

You are given two integers num and sum.

A positive integer is defined as good if:

  • It contains exactly num digits without leading zeros.

  • The sum of its digits equals sum.

The score of a good integer is the sum of the squares of its digits.

Return the good integer that achieves the maximum score as a string. If there are multiple good integers that achieve the maximum score, return the largest one among them. If no good integer exists, return an empty string "".

Constraints:

  • 1≤1 \leq num ≤2imes105\leq 2 imes 10^5

  • 1≤1 \leq sum ≤2imes106\leq 2 imes 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximize Sum of Squares of Digits

Try to solve the Maximize Sum of Squares of Digits problem.

Statement

You are given two integers num and sum.

A positive integer is defined as good if:

  • It contains exactly num digits without leading zeros.

  • The sum of its digits equals sum.

The score of a good integer is the sum of the squares of its digits.

Return the good integer that achieves the maximum score as a string. If there are multiple good integers that achieve the maximum score, return the largest one among them. If no good integer exists, return an empty string "".

Constraints:

  • 1≤1 \leq num ≤2imes105\leq 2 imes 10^5

  • 1≤1 \leq sum ≤2imes106\leq 2 imes 10^6