All problems
0508EasyMathEnumeration

Next Shelf Label

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3345Smallest Divisible Digit Product I

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A stockroom numbers its shelves with positive whole numbers. A shelf label is valid for a crate of type t when the product of the label's decimal digits is a multiple of t.

The next free shelf is n, and the crate may be placed on shelf n or on any higher-numbered shelf. Return the smallest label at or above n that is valid for t.

A label containing the digit 0 has a digit product of 0, and 0 counts as a multiple of every positive t.

Examples

Example 1

Input
n = 15, t = 7
Output
17

Shelf 15 has digit product 5 and shelf 16 has digit product 6, neither of which is a multiple of 7. Shelf 17 has digit product 7.

Example 2

Input
n = 16, t = 10
Output
20

Shelves 16 through 19 have digit products 6, 7, 8 and 9. Shelf 20 has digit product 0, which counts as a multiple of 10.

Example 3

Input
n = 99, t = 9
Output
99

Shelf 99 has digit product 81, and 81 is 9 times 9.

Constraints

  • 1 <= n <= 100
  • 1 <= t <= 10

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def smallest_shelf_label(n: int, t: int) -> int:
Java
public int smallestShelfLabel(int n, int t)
September 7
Apply