Skip to content

Practice Minimum Addition to Make Integer Beautiful

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2457
LeetCode Problem

Minimum Addition to Make Integer Beautiful

Problem Statement

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 such that n + x is beautiful. The input will be generated such that it is always possible to make n beautiful.

Source: Minimum Addition to Make Integer Beautiful on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 16, target = 6
Output
4

# Example 2

Input
n = 467, target = 6
Output
33

# Example 3

Input
n = 1, target = 1
Output
0

Constraints

1 <= n <= 10^12
1 <= target <= 150
The input will be generated such that it is always possible to make n beautiful.

Related LeetCode Problems

Practice more problems similar to Minimum Addition to Make Integer Beautiful.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.