2457. Minimum Addition to Make Integer Beautiful

Medium

443

20

You are given two positive integers `n`

and `target`

.

An integer is considered **beautiful** if the sum of its digits is less than or equal to `target`

.

Return the *minimum non-negative integer *

`x`

`n + x`

`n`

beautiful.

**Example 1:**

Input:n = 16, target = 6Output:4Explanation:Initially n is 16 and its digit sum is 1 + 6 = 7. After adding 4, n becomes 20 and digit sum becomes 2 + 0 = 2. It can be shown that we can not make n beautiful with adding non-negative integer less than 4.

**Example 2:**

Input:n = 467, target = 6Output:33Explanation:Initially n is 467 and its digit sum is 4 + 6 + 7 = 17. After adding 33, n becomes 500 and digit sum becomes 5 + 0 + 0 = 5. It can be shown that we can not make n beautiful with adding non-negative integer less than 33.

**Example 3:**

Input:n = 1, target = 1Output:0Explanation:Initially n is 1 and its digit sum is 1, which is already smaller than or equal to target.

**Constraints:**

`1 <= n <= 10`

^{12}`1 <= target <= 150`

- The input will be generated such that it is always possible to make
`n`

beautiful.

Accepted

15.9K

Submissions

43K

Acceptance Rate

36.9%

Seen this question in a real interview before?

1/4

Yes

No

Discussion (0)

Related Topics

Copyright ©️ 2023 LeetCode All rights reserved