Smallest Divisible Digit Product I

EasyMathEnumeration

Solution

export function smallestNumber(n: number, t: number): number {
  let curr = n;
  while (productDigits(curr) % t !== 0) {
    curr += 1;
  }
  return curr;
}
 
function productDigits(num: number) {
  return [...num.toString()].reduce((acc, digit) => acc * +digit, 1);
}

Complexity

  • Time: O(t)O(t)
  • Space: O(1)O(1)