Company: Intuit_30nov
Difficulty: medium
Smallest Multiple Problem Description You are given an integer n and a set of k allowed digits allowed_digits . Find the smallest number num > 0 that is a multiple of n and satisfies both of the following conditions: Each digit of num is present in the set allowed_digits . A digit may be used any number of times, and you do not have to use every digit of the set. No two consecutive digits of num are equal. For example, 123 is allowed but 122 is not. num is written in decimal with no leading zero. If there is no such num , the answer is the string -1 . Input Format The first line contains two integers n and k , separated by a space. The second line contains the k digits of allowed_digits , separated by spaces, in strictly increasing order. Output Format Print the smallest multiple that satisfies both conditions on a single line, or -1 if no such multiple exists. The answer can be far longer than any built-in integer type holds — within these limits it may contain up to 7985 dec