Mid/SeniorHash TableMath

Smallest Integer Divisible by K

Given a positive integer k, find the length of the smallest positive integer n such that n is divisible by k, and n only contains the digit 1.

Return the length of n. If there is no such n, return -1.

Note: n may not fit in a 64-bit signed integer.

Example 1
Inputk = 1
Output1
The smallest answer is n = 1, which has length 1.
Example 2
Inputk = 2
Output-1
There is no such positive integer n divisible by 2.

Constraints

  • 1 <= k <= 10^5

Asked at 6 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate