670. Smallest Greater Multiple Made of Two Digits

Given three integers, k, digit1, and digit2, you want to find the smallest integer that is:

  • Larger than k,
  • A multiple of k, and
  • Comprised of only the digits digit1 and/or digit2.

Return the smallest such integer. If no such integer exists or the integer exceeds the limit of a signed 32-bit integer (231 - 1), return -1.

Example 1:

Input: k = 2, digit1 = 0, digit2 = 2

Output: 20

Explanation:

20 is the first integer larger than 2, a multiple of 2, and comprised of only the digits 0 and/or 2.

Example 2:

Input: k = 3, digit1 = 4, digit2 = 2

Output: 24

Explanation:

24 is the first integer larger than 3, a multiple of 3, and comprised of only the digits 4 and/or 2.

Now Your Turn!

Pick the correct output for the given input

Consider the input: k = 2, digit1 = 2, digit2 = 5. What is the the smallest valid number?

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= k <= 1000
  • 0 <= digit1 <= 9
  • 0 <= digit2 <= 9

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
int findInteger(int k, int digit1, int digit2) {
// Your code goes here
}
};
 
Test Case

Input:

Digit1
Digit2
K