The Zappos Family interview question

An integer whose base-ten representation consists of only zero and one is called a "zero-one". given an arbitrary integer N, find the smallest "zero-one" integer S which is the multiple of N. (It is mathematically guaranteed that every N has such an S). Constraint: 0 < N < 100,000 Sample Input: 4 Sample Output: 100

Interview Answers

Anonymous

18 Feb 2016

i=1 while True: if int(bin(i)[2:])%n==0: return int(bin(i)[2:]) i+=1

Anonymous

5 Feb 2017

public static int smallestZeroOne(int num) { if(10%num==0) return 10; List list = new ArrayList(); list.add(10); List tempList = new ArrayList(); while(true) { for(Integer number : list) { int a = number * 10 + 0; if(a%num==0) return a; tempList.add(a); int b = number * 10 + 10; if(b%num==0) return b; tempList.add(b); } list.clear(); list.addAll(tempList); tempList.clear(); } }