Tap here to switch tabs
Problem
Submissions

Problem: Largest Integer With Given Digit Sum

Largest Integer With Given Digit Sum asks you to find the greatest nonnegative integer with at most n digits whose digits add up to s, or return -1 when impossible.

Statement

Given two integers n and s, determine the largest nonnegative integer with at most n digits such that the sum of its digits is equal to s. If no such integer exists, return −1-1.

Constraints:

  • 1≤1 \leq n ≤5\leq 5

  • 0≤0 \leq s ≤100\leq 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Largest Integer With Given Digit Sum

Largest Integer With Given Digit Sum asks you to find the greatest nonnegative integer with at most n digits whose digits add up to s, or return -1 when impossible.

Statement

Given two integers n and s, determine the largest nonnegative integer with at most n digits such that the sum of its digits is equal to s. If no such integer exists, return −1-1.

Constraints:

  • 1≤1 \leq n ≤5\leq 5

  • 0≤0 \leq s ≤100\leq 100