Problem · Breadth First Search

Smallest Binary-Digit Multiple

Learn this problem
MediumMyntra logoMyntraINTERNONSITE INTERVIEW

Problem statement

Given a positive integer n, return the numerically smallest positive decimal integer that is divisible by n and whose decimal representation contains only the digits 0 and 1.

The representation must begin with 1. Return the result as a string because it may not fit in a built-in integer type.

Function

smallestBinaryDigitMultiple(n: int) → String

Examples

Example 1

n = 2return = "10"

The decimal number 10 uses only allowed digits and is divisible by 2.

Example 2

n = 3return = "111"

Neither 1, 10, 11, 100, 101, nor 110 is divisible by 3; 111 is the first valid number.

Example 3

n = 7return = "1001"

The value 1001 equals 7 multiplied by 143.

Constraints

  • 1 <= n <= 20000.

More Myntra problems

drafts saved locally
public String smallestBinaryDigitMultiple(int n) {
    // Return the smallest valid decimal representation.
}
n2
expected"10"
checking account